constants question
Lars Poeschel
larsi@wh2.tu-dresden.de
Thu Feb 7 12:39:00 GMT 2008
-----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-----
More information about the Gcc-help
mailing list