This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: constants question
- From: Lars Poeschel <larsi at wh2 dot tu-dresden dot de>
- To: Eljay Love-Jensen <eljay at adobe dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Thu, 7 Feb 2008 13:39:38 +0100
- Subject: Re: constants question
- References: <C23B7B0D-0352-4B8D-ABF6-B49E0411EE75@wh2.tu-dresden.de> <47A9D8DB.2090301@adobe.com>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Am 06.02.2008 um 16:57 schrieb Eljay Love-Jensen:
Hi Lars,
Here bar is a variable:
char const* const bar = "bar";
I realize that bar is a const pointer to const char (array). But
the bar identifier itself is a fixed variable, and not a constant.
Here foo is a constant:
char const foo[] = "foo";
It's easy to conflate foo for a pointer, since, in C (and C++),
array constants degenerate into pointers quite promiscuously. Just
look at them funny, and they turn into pointers, as if you had
typed &foo[0].
Hence you can do this:
char const* const quux[] =
{
foo
};
But you cannot do this:
char const* const baz[] =
{
bar
};
C++ has slightly different rules, so it can do the later.
HTH,
--Eljay
Thanks a lot for this explanation, it is a bit more clear for me now!
Lars
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)
iEYEARECAAYFAkeq/AsACgkQ3m3cZ1XsbwfhnQCfUeLb1pJglyqWhhpsHdJ9Cxxl
H3sAni0Jq3N/Cuj0Qpr0L5bR2S0bvf6V
=+CGR
-----END PGP SIGNATURE-----