This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
A simple C question?
- To: EGCS Mailing List <egcs at egcs dot cygnus dot com>
- Subject: A simple C question?
- From: "Steven W. Orr" <steveo at world dot std dot com>
- Date: Wed, 22 Sep 1999 22:11:29 -0400 (EDT)
- Reply-To: steveo at world dot std dot com
typedef char foo[64];
foo bar;
void f ( foo *xxx )
{
return;
}
int main ()
{
f ( &bar );
return 0;
}
The program above is confusing the hell out of me. It gets no
warnings when I compile with egcs (even with -Wall) but I get a warning
when I compile with the cc compiler with no options on the alpha/Digital
Unix setup.
My first question is:
What should happen on the call to f? The warning I get from dec cc
says
In this statement, the referenced type of the
pointer value "&bar" is "signed char", which is not compatible with
"arry [64] of signed char". (ptrmismatch)
egcs gives no such warning.
Which compiler is correct?
The second question requires that I change the test program
typedef char foo[64];
foo bar;
void f ( foo xxx )
{
return;
}
int main ()
{
f ( bar );
return 0;
}
The change is that the variable of type foo is not being passed by
reference. Am I correct that bar is a scalar variable and that as
such it should be a 64 byte push onto the stack? Same as passing a
structure by value?
In both cases it turns out to be a reference parameter, with only a
pointer getting pushed on the stack.
This is driving me nutsola!
--
-Time flies like the wind. Fruit flies like a banana. steveo@world.std.com-
-Stranger things have happened but none stranger than this. Steven W. Orr-
Does your driver's license say Organ Donor?Black holes are where God \
-------divided by zero. Listen to me! We are all individuals!---------