linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Attenberger <fattenberger@onlinehome.de>
To: Sandro Dangui <sdangui@nortelnetworks.com>,
	linux-c-programming@vger.kernel.org
Subject: Re: literal constant..
Date: Tue, 03 Feb 2004 15:34:00 +0100	[thread overview]
Message-ID: <401FB158.40408@onlinehome.de> (raw)
In-Reply-To: <31E38B53D182D51195FA00508BE3A334033CA936@zwnbc004.cala.nortel.com>

char c[1]="c" is an unlucky example, it seems to be like this:
char c* = "c"; // make c point to "c\0".
char c[1] = "c"; // make c point to an undifined array of char of length 
1, set last char to '\0', _after_ that overwrite the array with "c", 
since "c" is just as long as the whole array, the \0 gets overwritten.

To get the second example behave equal to the first, it needs to be:
char c[2] = "c"; // char[0] == 'c', char[1] == '\0'.

So much to code difference.

char c[] is however a constant pointer, so you cannot reassign it.
That doesn't have to result in any assembler code difference at all, its 
just the compiler that complains.

flo

  reply	other threads:[~2004-02-03 14:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-03 11:41 literal constant Sandro Dangui
2004-02-03 14:34 ` Florian Attenberger [this message]
2004-02-03 15:04   ` John T. Williams
  -- strict thread matches above, loose matches on Subject: below --
2004-02-03  6:46 Vadiraj C S
     [not found] ` <006601c3ea24$c694d230$ed64a8c0@descartes>
2004-02-03  7:34   ` Vadiraj C S
2004-02-03 15:07 ` Glynn Clements

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=401FB158.40408@onlinehome.de \
    --to=fattenberger@onlinehome.de \
    --cc=linux-c-programming@vger.kernel.org \
    --cc=sdangui@nortelnetworks.com \
    /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 NNTP newsgroup(s).