* #if __GNUC__ > 2 ..
@ 2017-06-18 17:08 Jan Nieuwenhuizen
2017-06-18 19:33 ` Mark H Weaver
0 siblings, 1 reply; 3+ messages in thread
From: Jan Nieuwenhuizen @ 2017-06-18 17:08 UTC (permalink / raw)
To: Matt Wette; +Cc: guile-devel
Hi Matt!
When I use Nyacc to parse things like
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
#else
# define _GL_ATTRIBUTE_PURE /* empty */
#endif
I get
foo.c:1: undefined identifier: "__GNUC__"
foo.c:1: CPP error
I have been avoiding this using #:cpp-defs '( ... "__GNUC__=0" ) for Mes
but for real projects that put gcc-specific things inside
#ifdef __GCC__
#endif
that does not work. I'm trying to compile different things currently,
like 8cc, pcc and Guile's eval.c-- without much success ATM--, changing
and editing lots of things like these defines but it is getting hairy
now.
Greetings,
janneke
--
Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: #if __GNUC__ > 2 ..
2017-06-18 17:08 #if __GNUC__ > 2 Jan Nieuwenhuizen
@ 2017-06-18 19:33 ` Mark H Weaver
[not found] ` <CAO0Y5bVWHBXGt9aBU3yBSxr5ZNc8EAvcMXA-_Z46T3_5eG-oPw@mail.gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Mark H Weaver @ 2017-06-18 19:33 UTC (permalink / raw)
To: Jan Nieuwenhuizen; +Cc: guile-devel, Matt Wette
Jan Nieuwenhuizen <janneke@gnu.org> writes:
> Hi Matt!
>
> When I use Nyacc to parse things like
>
> #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
> # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
> #else
> # define _GL_ATTRIBUTE_PURE /* empty */
> #endif
>
> I get
>
> foo.c:1: undefined identifier: "__GNUC__"
> foo.c:1: CPP error
This looks like a problem in Nyacc. Within the condition of an "#if" or
"#elif" preprocessor form, after macro expansion is performed, all
remaining identifiers are replaced with 0. See section 6.10.1
(Conditional inclusion) paragraph 4 of C99.
Mark
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: #if __GNUC__ > 2 ..
[not found] ` <CAO0Y5bVWHBXGt9aBU3yBSxr5ZNc8EAvcMXA-_Z46T3_5eG-oPw@mail.gmail.com>
@ 2017-06-18 21:37 ` Matt Wette
0 siblings, 0 replies; 3+ messages in thread
From: Matt Wette @ 2017-06-18 21:37 UTC (permalink / raw)
To: Mark H Weaver, Jan Nieuwenhuizen; +Cc: guile-devel
With patch below, this looks to be working. I will update and release later today. — Matt
diff --git a/module/nyacc/lang/c99/cpp.scm b/module/nyacc/lang/c99/cpp.scm
index 7ea57f7..511553a 100644
--- a/module/nyacc/lang/c99/cpp.scm
+++ b/module/nyacc/lang/c99/cpp.scm
@@ -230,7 +230,7 @@
((or) (if (and (zero? (ev1 tree)) (zero? (ev2 tree))) 0 1))
((and) (if (or (zero? (ev1 tree)) (zero? (ev2 tree))) 0 1))
((cond-expr) (if (zero? (ev1 tree)) (ev3 tree) (ev2 tree)))
- ((ident) (cpp-err "undefined identifier: ~S" (cadr tree)))
+ ((ident) 0)
(else (error "incomplete implementation"))))))
(eval-expr tree)))
@@ -464,6 +464,7 @@
;; @deffn {Procedure} eval-cpp-cond-text text defs => string
;; Evaluate CPP condition expression (text).
+;; Undefined identifiers are replaced with @code{0}.
;; @end deffn
(define (eval-cpp-cond-text text defs)
(with-throw-handler
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-06-18 21:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-18 17:08 #if __GNUC__ > 2 Jan Nieuwenhuizen
2017-06-18 19:33 ` Mark H Weaver
[not found] ` <CAO0Y5bVWHBXGt9aBU3yBSxr5ZNc8EAvcMXA-_Z46T3_5eG-oPw@mail.gmail.com>
2017-06-18 21:37 ` Matt Wette
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).