This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

A simple C question?


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!---------


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]