Mail Archives: djgpp/1996/01/26/23:06:50
The code below is self-explanatory. Any ideas why GCC/DJGPP fails to
compile this with USE_ARRAY defined. FWIW...Borland C 3.1, Turbo
C 2.0 and Microsoft C 6.0a have no problem -- with all warnings
enabled in the case of the latter 3 compilers.
/*
If USE_ARRAY is defined, gcc emits:
gcc -DUSE_ARRAY struct-members.c -o struct-members
struct-members.c: In function `main':
struct-members.c:56: invalid use of non-lvalue array
There's no problem if the structure member is a pointer to char.
*/
#include <stdio.h>
#ifdef USE_ARRAY
#define S_TYPE s[81]
#define S_HOW "an array"
#else
#define S_TYPE *s
#define S_HOW "pointer to char"
#endif
typedef struct {
int i;
char S_TYPE;
} struct_t;
struct_t func(void)
{
static struct_t s = { 100, "string as " S_HOW };
return s;
}
int main(void)
{
struct_t s;
s = func();
printf("%d - %s\n", s.i, s.s); /* OK */
printf("%d - %s\n", func().i, func().s); /* Fails */
return 0;
}
--
=============================================================================
Bob Nelson: Dallas, Texas, U.S.A. - bnelson AT netcom DOT com
Linux for fun, M$ for $$$...and the NFL for what really counts!
=============================================================================
- Raw text -