T
Tomás Ó hÉilidhe
I've been developing a C89 microcontroller application for a while
now and I've been testing its compilation using gcc. I've gotten zero
errors and zero warnings with gcc, but now that I've moved over to the
micrcontroller compiler I'm getting all sorts of errors.
One thing I'd like to clarify is the need (in C89) for a compile-
time constant in the initialiser of a variable. The compiler rejects the
following source file:
/* Start foo.c */
int const a = 7;
int b = a;
/* End foo.c */
It says that the initialiser of "b" needs to be a compile-time
constant. Is it true that the initialiser of a non-const global object
needs to be a compile-time constant in C89? Or is this just a short
coming of the compiler?
Another related question:
/* Start bar.c */
void Func(void)
{
int const x = 7;
int const y = x;
}
/* End bar.c
In the snippet immediately above, the compiler fails because y's
initialiser isn't a compile-time constant. How does C89 view this? (If
"y" is made non-const, then the compiler accepts the code, but I'm
wondering if a _const_ local automatic variable's initialiser must be a
compile-time constant in C89?)
now and I've been testing its compilation using gcc. I've gotten zero
errors and zero warnings with gcc, but now that I've moved over to the
micrcontroller compiler I'm getting all sorts of errors.
One thing I'd like to clarify is the need (in C89) for a compile-
time constant in the initialiser of a variable. The compiler rejects the
following source file:
/* Start foo.c */
int const a = 7;
int b = a;
/* End foo.c */
It says that the initialiser of "b" needs to be a compile-time
constant. Is it true that the initialiser of a non-const global object
needs to be a compile-time constant in C89? Or is this just a short
coming of the compiler?
Another related question:
/* Start bar.c */
void Func(void)
{
int const x = 7;
int const y = x;
}
/* End bar.c
In the snippet immediately above, the compiler fails because y's
initialiser isn't a compile-time constant. How does C89 view this? (If
"y" is made non-const, then the compiler accepts the code, but I'm
wondering if a _const_ local automatic variable's initialiser must be a
compile-time constant in C89?)