public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Aseem Rastogi <aseem@india.tejasnetworks.com>
To: John Love-Jensen <eljay@adobe.com>
Cc: Trevis Rothwell <tjr@gnu.org>, MSX to GCC <gcc-help@gcc.gnu.org>
Subject: Re: extern question
Date: Tue, 06 Jun 2006 14:08:00 -0000	[thread overview]
Message-ID: <44858D28.90403@india.tejasnetworks.com> (raw)
In-Reply-To: <C0AAF48F.123AB%eljay@adobe.com>

interestingly (or at least i think so :-) ), the code snippet that 
Trevis has given compiles and links using gcc BUT fails to link under 
g++ (2 times defined problem). being a C++ programmer, this is what i 
expected but was surprised to see that gcc compiles such a code.

i investigated a bit. if we just do 'gcc -c bar.c' and then 'nm bar.o', 
then larry is shown as "C" symbol which means common (weak) symbol. 
whereas if we do 'g++ -c bar.c' and then 'nm bar.o', then larry is shown 
as "B" symbol which is global initialized data.

could it have something to do with the fact that global variables are 
automaically initialized to their default values in C++ ??

John Love-Jensen wrote:

>Hi Trevis,
>
>>should I even be allowed to declare "larry" in both foo.c and
>>bar.c ?  If so, why is that not seen as a problem?
>>
>
>You can declare larry as many times as you want.  You've declared it in
>main.c and in bar.c.
>
>You can only define larry once.  You've defined it in bar.c.
>
>If you change the declaration of larry in bar.c to a definition, then you've
>defined it too many times (i.e., more than once).
>
>HTH,
>--Eljay
>
>


-- 
Nothing will work unless u do.



  parent reply	other threads:[~2006-06-06 14:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-06 13:50 Trevis Rothwell
2006-06-06 14:00 ` John Love-Jensen
2006-06-06 14:05   ` John Love-Jensen
2006-06-06 14:08   ` Aseem Rastogi [this message]
2006-06-06 14:12     ` John Love-Jensen
2006-06-06 14:31 ` Andrew Haley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=44858D28.90403@india.tejasnetworks.com \
    --to=aseem@india.tejasnetworks.com \
    --cc=eljay@adobe.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=tjr@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).