Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #30428

Re: Struct assignment

Date 2013-01-21 12:02 +1100
From Russell Shaw <rjshawN_o@s_pam.netspace.net.au>
Newsgroups comp.lang.c
Subject Re: Struct assignment
References (1 earlier) <kde706$3t0$1@dont-email.me> <simqs9-ue9.ln1@main.anatron.com.au> <kdehee$3ni$1@dont-email.me> <bturs9-mi4.ln1@main.anatron.com.au> <kdgtp3$7n1$1@dont-email.me>
Message-ID <hmgus9-9b5.ln1@main.anatron.com.au> (permalink)
Organization Unlimited download news at news.astraweb.com

Show all headers | View raw


On 21/01/13 01:08, Eric Sosman wrote:
> On 1/19/2013 8:46 PM, Russell Shaw wrote:
>> [... two "identical" struct types are incompatible ...]
>>
>> The problem is that if you #include the declaration of an anonymous
>> struct sa from a separate translation unit, then the compiler complains
>> about sb = sa.
>
> I don't understand this. A "translation unit" is all of
> the source the compiler sees at one time: The original source
> file, all the files and headers it #includes, all the files and
> headers they in turn #include, all macros defined on compiler
> command lines or whatever, ... If you #include a declaration,
> that declaration is part of *the* translation unit; it is not
> an interloper from "a separate translation unit."

Precisely. Because of that problem, i could not see how declarations from 
separate translation units should be compatible, when including a header with 
the second declaration now becomes a part of the first translation unit anyway, 
thus making the point mute.

I'll go with the interpretation as stated in this group, because it makes for 
less complication in the compiler, and is safer to use.

>> If you *don't* #include the declaration of an anonymous struct sa from a
>> separate translation unit, then the compiler complains that sa isn't
>> declared.
>
> Same disconnect; I still don't understand you.
>
>> In what use-case can sb = sa be done without complaint?
>
> I showed a few elsethread; here's one of them again:
>
> struct { int a; } sa, sb;
> ...
> sa.a = 42;
> sb = sa;
>

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Struct assignment Russell Shaw <rjshawN_o@s_pam.netspace.net.au> - 2013-01-19 23:09 +1100
  Re: Struct assignment Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-01-19 08:27 -0500
    Re: Struct assignment Russell Shaw <rjshawN_o@s_pam.netspace.net.au> - 2013-01-20 01:18 +1100
      Re: Struct assignment "BartC" <bc@freeuk.com> - 2013-01-19 14:59 +0000
      Re: Struct assignment Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-01-19 11:25 -0500
        Re: Struct assignment Russell Shaw <rjshawN_o@s_pam.netspace.net.au> - 2013-01-20 12:46 +1100
          Re: Struct assignment Bart van Ingen Schenau <bart@ingen.ddns.info.invalid> - 2013-01-20 09:20 +0000
          Re: Struct assignment Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-01-20 09:08 -0500
            Re: Struct assignment Russell Shaw <rjshawN_o@s_pam.netspace.net.au> - 2013-01-21 12:02 +1100
              Re: Struct assignment Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-01-20 22:08 -0500
                Re: Struct assignment James Kuyper <jameskuyper@verizon.net> - 2013-01-20 23:21 -0500
              Re: Struct assignment James Kuyper <jameskuyper@verizon.net> - 2013-01-21 08:23 -0500
                Re: Struct assignment Russell Shaw <rjshawN_o@s_pam.netspace.net.au> - 2013-01-22 13:33 +1100
                Re: Struct assignment Russell Shaw <rjshawN_o@s_pam.netspace.net.au> - 2013-01-23 19:53 +1100
      Re: Struct assignment Shao Miller <sha0.miller@gmail.com> - 2013-01-19 11:45 -0500
        Re: Struct assignment Russell Shaw <rjshawN_o@s_pam.netspace.net.au> - 2013-01-20 13:21 +1100
          Re: Struct assignment Shao Miller <sha0.miller@gmail.com> - 2013-01-20 01:06 -0500
            Re: Struct assignment Russell Shaw <rjshawN_o@s_pam.netspace.net.au> - 2013-01-20 18:03 +1100
  Re: Struct assignment glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-19 19:18 +0000
    Re: Struct assignment James Kuyper <jameskuyper@verizon.net> - 2013-01-19 15:22 -0500
      Re: Struct assignment Shao Miller <sha0.miller@gmail.com> - 2013-01-19 15:47 -0500
      Re: Struct assignment Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-01-19 17:56 -0500
        Re: Struct assignment Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-20 12:12 -0800
  Re: Struct assignment falk@rahul.net (Edward A. Falk) - 2013-01-19 23:41 +0000
    Re: Struct assignment glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-20 01:01 +0000
    Re: Struct assignment James Kuyper <jameskuyper@verizon.net> - 2013-01-19 20:53 -0500
      Re: Struct assignment Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-20 12:03 -0800

csiph-web