Re: constants question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----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-----

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux