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 :-) 4 3054
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 ---
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.
--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net
--
Posted via a free Usenet account from http://www.teranews.com
jaime <no*********@example.orgwrites:
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)
Short: no.
Medium: not if you want portable code.
Long: read all of section 6.6 of the standard. The trouble is it says
what you *can* have. The value of a variable, const, or otherwise is
not one of these.
Section 6.6 does permit implementations to allow other forms, so you
might be able to do it, but your code will not be portable. Such am
implementation would be violating the spirit in which const was
introduced (to signify a read-only, run-time object).
--
Ben.
jaime <no*********@example.orgwrites:
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").
[...]
No, "const" in C really means "read-only", not "constant".
Your Google search probably confused you because <OT>x is a constant
expression in C++</OT>.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister" This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Joshua Beall |
last post by:
Hi All,
What does the "const" reserved word in PHP4 do? I know it is a reserved
word in PHP4, but the only references I can find to it are for PHP5.
Here's what I want to do:
Rather than...
|
by: CoolPint |
last post by:
Can anyone clearly explain the difference between constant reference to
pointers and reference to constant pointers?
What is const int * & ?
Is it a constant reference to a pointer to an...
|
by: Charlie Zender |
last post by:
Hi,
I am unable to compile a large body of code with extremely pedantic
compile time checks activate, so that warnings cause errors.
With GCC 3.3.1, I do this with
gcc -std=c99 -pedantic...
|
by: PB |
last post by:
Hi !
I have the following code, which I am using in an Embedded systems,
c-compiler.. However I see the same problem with GCC too..
I need the last 10 bits of an address pointer, which is...
|
by: hn.ft.pris |
last post by:
Hi:
I have the following simple program:
#include<iostream>
using namespace std;
int main(int argc, char* argv){
const double L = 1.234;
const int T = static_cast<const int>(L);
int arr;
|
by: liujiaping |
last post by:
I'm confused about the program below:
int
main(int argc, char* argv)
{
char str1 = "abc";
char str2 = "abc";
const char str3 = "abc";
const char str4 = "abc";
const char* str5 = "abc";
|
by: Jess |
last post by:
Hello,
If I have a constant array, i.e. it's elements aren't changed, should
I declare it as:
const int a = {1,2,3};
or
int const a = {1,2,3}
|
by: Luna Moon |
last post by:
Hi all,
I just couldn't get myself clear about the usage of "const" in front
of and/or behind variables, pointers, classes, objects and
functions...
It's too confusing... any good clear...
|
by: Adem |
last post by:
C/C++ language proposal:
Change the 'case expression' from "integral constant-expression" to "integral expression"
The C++ Standard (ISO/IEC 14882, Second edition, 2003-10-15)
says under...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |