Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!crdgw1!camelback!volpe From: volpe@camelback.crd.ge.com (Christopher R Volpe) Newsgroups: comp.lang.c Subject: Re: Problem with #define'd macro... Message-ID: <18234@crdgw1.crd.ge.com> Date: 4 Apr 91 17:34:55 GMT References: <18146@crdgw1.crd.ge.com> <18200@crdgw1.crd.ge.com> <10903@ncar.ucar.edu> Sender: news@crdgw1.crd.ge.com Reply-To: volpe@camelback.crd.ge.com (Christopher R Volpe) Lines: 51 In article <10903@ncar.ucar.edu>, steve@groucho.ucar.edu (Steve Emmerson) writes: |>Whoops! Hang on a second! |> |>I said the expression was valid according to the K&R1 grammar. It is, |>however, quite invalid under Standard C: it cannot be generated from |>the grammar. |> |>The original question was in the context of K&R1 C. Ah, right. Sorry. Yes, it's valid under K&R1, and SunOS cc incorrectly flags it. Gcc -traditional also does the same incorrect thing. The default gcc (i.e. ansi) correctly flags it, but for the wrong reason. According to ANSI it's a pure syntax violation, but gcc reports "invalid lvalue in assignment". But that's because the "then" branch of the conditional isn't an lvalue. If we take advantage of GCC's generalized lvalues, we get the following: #include int main() { int a=0,b=0,c=0; c=0; /* This get's reported as invalid lhs of assignment c ? c = a : c = b ; */ /* This is a prefectly valid generalized lvalue */ (c ? a : b) = 5; /* This is a syntax error according to ANSI, but GCC treats it like the above */ c ? a : b = 5; } GCC behaves the same way with -ansi. However, it produces the "invalid lhs" again when using -pedantic. It never finds the syntax violation. |> |>Steve Emmerson steve@unidata.ucar.edu ...!ncar!unidata!steve ================== Chris Volpe G.E. Corporate R&D volpecr@crd.ge.com