From: Stephen Satchell <list@fluent2.pyramid.net>
To: Mohammed Khalid Ansari <khalid@ncst.ernet.in>
Cc: Glynn Clements <glynn.clements@virgin.net>,
linux c programming mailing list
<linux-c-programming@vger.kernel.org>
Subject: Re: strange behavious
Date: Wed, 25 Dec 2002 13:39:44 -0800 [thread overview]
Message-ID: <5.2.0.9.0.20021225132730.01d204d0@fluent2.pyramid.net> (raw)
In-Reply-To: <Pine.LNX.4.33.0212251757430.11856-100000@soochak.ncst.erne t.in>
At 05:58 PM 12/25/02 +0530, Mohammed Khalid Ansari wrote:
> > Look at the type for string constants. It is "const array of char".
>
>I haven't defined them to be const, please see above.
You misunderstand, the inherent type for string constants is "const array
of char". Let's look at what you are doing.
the statement
char *words[] = {"mohammed", "khalid", "ansari"};
defines a array of three pointers to char, and initializes those pointer to
three strings which have the type "const array of char", which is promoted
to "pointer to const char". A way to rewrite this statement so the result
is identical but shows the exact typing is this:
const char w1[9] = {'m','o','h','a','m','m','e','d',0};
const char w2[7] = {'k','h','a','l'.'i'.'d',0};
const char w3[7] = {'a','n','s','a','r','i',0};
char *words[3] = {w1, w2, w3};
That is what the "shorthand" in the first statement expands to, if you
apply the rules of ANSI to it.
Just remember that constants have a type associated with them, and you HAVE
LITTLE CONTROL OF THE TYPE assigned to constants. GCC allows you to say
whether a "plain" char is signed or unsigned, but not (to the best of my
knowledge) whether you can remove the "const" attribute from a constant
character.
Investigate whether you can ask GCC to use the old Unix conventions for
strings...but I wouldn't recommend it for new programs, and would strongly
recommend doing the Right Thing(tm) and port the old code to the new
semantics, for they will keep you from going down a road that is full of
astonishment.
Stephen
next prev parent reply other threads:[~2002-12-25 21:39 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-12-21 5:25 strange behavious Mohammed Khalid Ansari
2002-12-23 8:19 ` Glynn Clements
2002-12-24 5:20 ` Mohammed Khalid Ansari
2002-12-25 9:50 ` Glynn Clements
[not found] ` <Pine.LNX.4.33.0212241046350.31854-100000@soochak.ncst.erne t.in>
2002-12-24 10:12 ` Stephen Satchell
2002-12-25 12:28 ` Mohammed Khalid Ansari
2002-12-25 13:58 ` Glynn Clements
[not found] ` <Pine.LNX.4.33.0212251757430.11856-100000@soochak.ncst.erne t.in>
2002-12-25 21:39 ` Stephen Satchell [this message]
-- strict thread matches above, loose matches on Subject: below --
2002-12-23 8:27 Alvarez Alberto-AALVARB1
2002-12-24 5:15 ` Mohammed Khalid Ansari
2002-12-25 9:55 ` Glynn Clements
2002-12-25 12:31 ` Mohammed Khalid Ansari
2002-12-25 13:44 ` 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=5.2.0.9.0.20021225132730.01d204d0@fluent2.pyramid.net \
--to=list@fluent2.pyramid.net \
--cc=glynn.clements@virgin.net \
--cc=khalid@ncst.ernet.in \
--cc=linux-c-programming@vger.kernel.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 NNTP newsgroup(s).