467,148 Members | 1,310 Online

# (C99) Does "const int x=5;" make x a "constant expression"?

 Hi again all. Given the line: const int x=5; Can I then use "x" as a constant expression? (By "constant expression", I mean "constant expression" as defined in the C99 standard) I've been searching google for 2 days now trying to answer this myself, and I'm just getting more and more confused (some things I read make me think "yes", while some things I read make me think "no"). I have many questions I'd like to ask on this topic, but rather than bore you all rigid with the results of all of my research (points for and against), I thought I'd just try this short question first. Also, could anyone answering please give me an idea of how I can infer the answer by reading the "Standard" (which I _think_ is currently ISO/IEC 9899:TC2). So, baffled once again, I humbly seek wise words from the council of elders... Ta, Jaime :-) Jun 16 '07 #1
• viewed: 2671
Share:
4 Replies
 jaime wrote: Hi again all. Given the line: const int x=5; Can I then use "x" as a constant expression? (By "constant expression", I mean "constant expression" as defined in the C99 standard) I've been searching google for 2 days now trying to answer this myself, and I'm just getting more and more confused (some things I read make me think "yes", while some things I read make me think "no"). I have many questions I'd like to ask on this topic, but rather than bore you all rigid with the results of all of my research (points for and against), I thought I'd just try this short question first. Also, could anyone answering please give me an idea of how I can infer the answer by reading the "Standard" (which I _think_ is currently ISO/IEC 9899:TC2). So, baffled once again, I humbly seek wise words from the council of elders... Ta, Jaime :-) No. const != constant in C. In your example.. const int x = 5; ...x is const and 5 is constant. You can't use x where you need a constant. -- Joe Wright "Everything should be made as simple as possible, but not simpler." --- Albert Einstein --- Jun 16 '07 #2
 jaime wrote: > Given the line: const int x=5; Can I then use "x" as a constant expression? (By "constant expression", I mean "constant expression" as defined in the C99 standard) No. It is a constant object, not expression. I.E. it cannot be altered. -- cbfalconer at maineline dot net -- Posted via a free Usenet account from http://www.teranews.com Jun 16 '07 #3
 jaime
 jaime x is a constant expression in C++. -- Keith Thompson (The_Other_Keith) ks***@mib.org San Diego Supercomputer Center <* "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" Jun 16 '07 #5

### This discussion thread is closed

Replies have been disabled for this discussion.

### Similar topics

 2 posts views Thread by Joshua Beall | last post: by 2 posts views Thread by CoolPint | last post: by 12 posts views Thread by Charlie Zender | last post: by 10 posts views Thread by PB | last post: by 13 posts views Thread by hn.ft.pris@gmail.com | last post: by 20 posts views Thread by liujiaping | last post: by 3 posts views Thread by Jess | last post: by 7 posts views Thread by Luna Moon | last post: by 56 posts views Thread by Adem | last post: by 6 posts views Thread by Otekpo Emmanuel | last post: by reply views Thread by SwissProgrammer | last post: by 2 posts views Thread by SwissProgrammer | last post: by 3 posts views Thread by SwissProgrammer | last post: by 2 posts views Thread by Firas Rihan | last post: by 3 posts views Thread by CD Tom | last post: by 1 post views Thread by AccessUser22 | last post: by 1 post views Thread by vinayak1209 | last post: by reply views Thread by Raftar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.