linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Shriramana Sharma <samjnaa@gmail.com>
To: Linux C Programming List <linux-c-programming@vger.kernel.org>
Subject: Re: can't initialize a constant using another constant?
Date: Thu, 28 Feb 2008 05:05:51 +0530	[thread overview]
Message-ID: <47C5F3D7.7020002@gmail.com> (raw)
In-Reply-To: <18373.19696.942794.821373@cerise.gclements.plus.com>

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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2008-02-27 23:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-26 14:32 can't initialize a constant using another constant? Shriramana Sharma
2008-02-27  8:09 ` Kristof Provost
2008-02-27  8:33   ` Kristof Provost
2008-02-27 11:43 ` Glynn Clements
2008-02-27 23:35   ` Shriramana Sharma [this message]
2008-02-28  9:52     ` 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=47C5F3D7.7020002@gmail.com \
    --to=samjnaa@gmail.com \
    --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).