Re: can't initialize a constant using another constant?

Shriramana Sharma <[email protected]>
Newsgroups org.kernel.vger.linux-c-programming
Message-ID <[email protected]>
Thanks to all those who replied. I am very sorry I did not specify the 
compiler version etc. I should have. It's gcc version 4.1.3 20070929 
(prerelease) (Ubuntu 4.1.2-16ubuntu2).

Glynn Clements wrote:
> In C, "const" is only relevant to pointer targets. Adding the "const"
> modifier to a variable has no effect.

I don't understand what you mean. I just tried gcc -o foo foo.c on:

# include <stdio.h>
main () {
         const int i = 1 ;
         i = 2 ;
         printf ( "%d\n", i ) ;
}

and I got:

foo.c: In function ‘main’:
foo.c:6: error: assignment of read-only variable ‘i’

So in what sense are you saying adding const to a variable has no effect?

Shriramana Sharma.
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.