![]() |
Re: Struct assignment
In article <u0fqs9-929.ln1@main.anatron.com.au>,
Russell Shaw <rjshawN_o@s_pam.netspace.net.au> wrote: >Hi, >In gcc-4.7 C99, i get an error (in a function scope): > > struct { > int a; > } sa; > > struct { > int a; > } sb; > > sb = sa; > >error: incompatible types when assigning to type 'struct <anonymous>' from type >'struct <anonymous>' You're asking rather a lot for the compiler to recognize that two different structures just happen to have been defined the same way. Try this: struct foo { int a; }; struct foo sa; struct foo sb; sb = sa; -- -Ed Falk, falk@despams.r.us.com http://thespamdiaries.blogspot.com/ |
Re: Struct assignment
Edward A. Falk <falk@rahul.net> wrote:
> In article <u0fqs9-929.ln1@main.anatron.com.au>, > Russell Shaw <rjshawN_o@s_pam.netspace.net.au> wrote: >>In gcc-4.7 C99, i get an error (in a function scope): >> struct { >> int a; >> } sa; >> struct { >> int a; >> } sb; >> sb = sa; >>error: incompatible types when assigning to type 'struct <anonymous>' from type >>'struct <anonymous>' > You're asking rather a lot for the compiler to recognize that two different > structures just happen to have been defined the same way. Well, it doesn't have to 'just' recognize it, but only test when it finds an actual operation. I believe that PL/I can do it. I am not sure what happens if you give PL/I a structure expression of incompatible structures. My guess is that it converts as appropriate. DCL 1 SA, 2 A FIXED BINARY(31,0); DCL 1 SB, 2 A FIXED BINARY(31,0); I am pretty sure that PL/I will let you do either SA=SB; or even SA=SA+SB; and, for extra challange: DCL 1 SC, 2 A FIXED BINARY(31,0); DCL 1 SD, 2 A FLOAT BINARY(53); SD=SD+SQRT(SC); -- glen |
Re: Struct assignment
On 01/19/2013 06:41 PM, Edward A. Falk wrote:
> In article <u0fqs9-929.ln1@main.anatron.com.au>, > Russell Shaw <rjshawN_o@s_pam.netspace.net.au> wrote: >> Hi, >> In gcc-4.7 C99, i get an error (in a function scope): >> >> struct { >> int a; >> } sa; >> >> struct { >> int a; >> } sb; >> >> sb = sa; >> >> error: incompatible types when assigning to type 'struct <anonymous>' from type >> 'struct <anonymous>' > > You're asking rather a lot for the compiler to recognize that two different > structures just happen to have been defined the same way. Perhaps - yet that is precisely what the standard would have required if they had been declared in two different translation units; it's only because they are in the same translation unit that they're not compatible (6.2.7p1). -- James Kuyper |
Re: Struct assignment
On 01/19/2013 06:41 PM, Edward A. Falk wrote:
> In article <u0fqs9-929.ln1@main.anatron.com.au>, > Russell Shaw <rjshawN_o@s_pam.netspace.net.au> wrote: >> Hi, >> In gcc-4.7 C99, i get an error (in a function scope): >> >> struct { >> int a; >> } sa; >> >> struct { >> int a; >> } sb; >> >> sb = sa; >> >> error: incompatible types when assigning to type 'struct <anonymous>' from type >> 'struct <anonymous>' > > You're asking rather a lot for the compiler to recognize that two different > structures just happen to have been defined the same way. Perhaps - yet that is precisely what the standard would have required if they had been declared in two different translation units; it's only because they are in the same translation unit that they're not compatible (6.2.7p1). -- James Kuyper |
Re: Struct assignment
James Kuyper <jameskuyper@verizon.net> writes:
> On 01/19/2013 06:41 PM, Edward A. Falk wrote: >> In article <u0fqs9-929.ln1@main.anatron.com.au>, >> Russell Shaw <rjshawN_o@s_pam.netspace.net.au> wrote: >>> Hi, >>> In gcc-4.7 C99, i get an error (in a function scope): >>> >>> struct { >>> int a; >>> } sa; >>> >>> struct { >>> int a; >>> } sb; >>> >>> sb = sa; >>> >>> error: incompatible types when assigning to type 'struct >>> <anonymous>' from type 'struct <anonymous>' >> >> You're asking rather a lot for the compiler to recognize that >> two different structures just happen to have been defined the >> same way. > > Perhaps - yet that is precisely what the standard would have > required if they had been declared in two different translation > units; [snip] I expect M. Kuyper means something different from what he is saying. C compilers don't even try to determine whether structs declared in different translation units are defined the same way, and certainly the Standard doesn't require them to do so. |
| All times are GMT. The time now is 12:33 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.