* CXX Compiler Barfs on traditional C cast
@ 2003-08-15 22:53 Bill Alexander
2003-08-15 22:56 ` Falk Hueffner
0 siblings, 1 reply; 3+ messages in thread
From: Bill Alexander @ 2003-08-15 22:53 UTC (permalink / raw)
Imagine I have the following code:
#include <stdio.h>
typedef struct { int a ; int b; int c; } foo;
#define FOOBLD(x,y,z) ((foo){(x),(y),(z)})
int main(void)
{
foo bar;
bar = FOOBLD(1,2,3);
printf("%d %d %d\n", bar.a, bar.b, bar.c);
return 0;
}
Say I save the file under two names: test.c and test.cc. Under Tru64
5.0A with CXX (whatever the stock revision is), I compile both files
with:
cxx test.c
cxx test.cc
The .c version works perfectly and as I'd expect in traditional C.
The .cc version has a compiler failure with something like:
"error: expected expression" where the macro with the cast shows up.
I can't reproduce this with other OS's compilers, and don't see any
other references on the 'net to this problem.
I need to get something like this working in order to remain
compatible with a large body of legacy code.
Does anyone have an idea about what I'm missing here?
Thanks in advance.
- Bill
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: CXX Compiler Barfs on traditional C cast
2003-08-15 22:53 CXX Compiler Barfs on traditional C cast Bill Alexander
@ 2003-08-15 22:56 ` Falk Hueffner
2003-08-18 17:04 ` Bill Alexander
0 siblings, 1 reply; 3+ messages in thread
From: Falk Hueffner @ 2003-08-15 22:56 UTC (permalink / raw)
w.f.alexander@attbi.com (Bill Alexander) writes:
> #define FOOBLD(x,y,z) ((foo){(x),(y),(z)})
>
> The .c version works perfectly and as I'd expect in traditional C.
> The .cc version has a compiler failure with something like:
> "error: expected expression" where the macro with the cast shows up.
This is not a "traditional cast". It's a compound literal. This was
only introduced in C99, whereas C++ is based on C89. Therefore, the
C++ compiler is correct in rejecting it.
--
Falk
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: CXX Compiler Barfs on traditional C cast
2003-08-15 22:56 ` Falk Hueffner
@ 2003-08-18 17:04 ` Bill Alexander
0 siblings, 0 replies; 3+ messages in thread
From: Bill Alexander @ 2003-08-18 17:04 UTC (permalink / raw)
Bummer! But thanks for the lesson. I guess I've started thinking of
c99 as "traditional" and didn't even consider this. I must be getting
lazy.
- Bill
Falk Hueffner <falk.hueffner@student.uni-tuebingen.de> wrote in message news:<87wudebkdo.fsf@student.uni-tuebingen.de>...
> w.f.alexander@attbi.com (Bill Alexander) writes:
>
> > #define FOOBLD(x,y,z) ((foo){(x),(y),(z)})
> >
> > The .c version works perfectly and as I'd expect in traditional C.
> > The .cc version has a compiler failure with something like:
> > "error: expected expression" where the macro with the cast shows up.
>
> This is not a "traditional cast". It's a compound literal. This was
> only introduced in C99, whereas C++ is based on C89. Therefore, the
> C++ compiler is correct in rejecting it.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-08-18 17:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-08-15 22:53 CXX Compiler Barfs on traditional C cast Bill Alexander
2003-08-15 22:56 ` Falk Hueffner
2003-08-18 17:04 ` Bill Alexander
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox