S
Stephan Beal
Hello, all!
i'm working on a program where i'm making heavy use of (...) arguments
and i have a question about them. It's all working fine and well, but
i'm getting a warning from one compiler which makes the think that
perhaps my usage isn't portable, and i want to find out what C says
about my use case (rather than what my compilers say).
Consider:
struct my_struct {
int i;
struct my_struct * left;
struct some_struct bar;
};
Now, assuming i have a routine:
void do_mything( struct context *, ... );
i'm calling that like:
static const my_struct end; /* special argument to signal end of list
*/
my_struct foo;
my_struct bar;
.... initialize structs ...
do_mything( myContext, foo, bar, end );
My question is simple: is it legal (strictly speaking) to pass objects
other than built-in types here? gcc and SunStudio compilers don't
complain about it and the code words as expected, but tcc says
"warning: assignment of read-only location" (but it still works as
expected), so my suspicion is that gcc and SunCC are being too lenient
on me and that tcc is trying to tip me off to a violation of the
standard.
If it makes a difference, i'm trying to code for pre-C99, but i also
don't mind if i have to rely on C99 features.
To cut off the anticipated counter-question in advance: "why not pass
pointers to my_struct instead?" The answer is:
a) i do. i have two variants of my routines: one takes a list of
pointers and one takes a list of value types.
b) both approaches have slightly different implications in my library
and both are useful in different contexts.
:-?
i'm working on a program where i'm making heavy use of (...) arguments
and i have a question about them. It's all working fine and well, but
i'm getting a warning from one compiler which makes the think that
perhaps my usage isn't portable, and i want to find out what C says
about my use case (rather than what my compilers say).
Consider:
struct my_struct {
int i;
struct my_struct * left;
struct some_struct bar;
};
Now, assuming i have a routine:
void do_mything( struct context *, ... );
i'm calling that like:
static const my_struct end; /* special argument to signal end of list
*/
my_struct foo;
my_struct bar;
.... initialize structs ...
do_mything( myContext, foo, bar, end );
My question is simple: is it legal (strictly speaking) to pass objects
other than built-in types here? gcc and SunStudio compilers don't
complain about it and the code words as expected, but tcc says
"warning: assignment of read-only location" (but it still works as
expected), so my suspicion is that gcc and SunCC are being too lenient
on me and that tcc is trying to tip me off to a violation of the
standard.
If it makes a difference, i'm trying to code for pre-C99, but i also
don't mind if i have to rely on C99 features.
To cut off the anticipated counter-question in advance: "why not pass
pointers to my_struct instead?" The answer is:
a) i do. i have two variants of my routines: one takes a list of
pointers and one takes a list of value types.
b) both approaches have slightly different implications in my library
and both are useful in different contexts.
:-?