Assume we have somewhere
typedef enum foo { A,B,C } foo;
Is C+1 a constant expression?
[
I want to write smth. like
char* strs[C+1]={"Astr","Bstr","Cstr"};
]
Could anyone help?
Regards,
Alex.
--
comp.lang.c.moderated - moderation address: cl**@plethora.net 12 1716
"Alexander Malkis" <al******@LOESCHEDIESline.cs.uni-sb.de> wrote in message
news:cl****************@plethora.net... Assume we have somewhere typedef enum foo { A,B,C } foo;
Is C+1 a constant expression?
Yes. [ I want to write smth. like char* strs[C+1]={"Astr","Bstr","Cstr"}; ]
Could anyone help?
It looks OK to me. Are you having trouble with it?
-Mike
No. Not yet.
Thank you.
Alex.
Mike Wahler wrote: "Alexander Malkis" <al******@LOESCHEDIESline.cs.uni-sb.de> wrote in message news:cl****************@plethora.net... Assume we have somewhere typedef enum foo { A,B,C } foo;
Is C+1 a constant expression?
Yes.
[ I want to write smth. like char* strs[C+1]={"Astr","Bstr","Cstr"}; ]
Could anyone help?
It looks OK to me. Are you having trouble with it?
-Mike
"Alexander Malkis" <al******@LOESCHEDIESline.cs.uni-sb.de> skrev i
meddelandet news:cl****************@plethora.net... Assume we have somewhere typedef enum foo { A,B,C } foo;
Is C+1 a constant expression?
That depends.
If the built-in operator+ is used, it is. If you have written an own
operator+(foo, int), it isn't.
--
Dag Henriksson
On 26 Feb 2004 21:56:14 GMT, Alexander Malkis
<al******@LOESCHEDIESline.cs.uni-sb.de> wrote: Assume we have somewhere typedef enum foo { A,B,C } foo;
Is C+1 a constant expression?
Yes. [ I want to write smth. like char* strs[C+1]={"Astr","Bstr","Cstr"}; ]
Could anyone help?
Well, you start up your text editor, and then type it in ;-)
Seriously, though, wouldn't just trying this in your compiler have been
less work than entering the names of all those newsgroups you've
cross-posted to?
Regards, Alex.
Leor Zolman
BD Software le**@bdsoft.com www.bdsoft.com -- On-Site Training in C/C++, Java, Perl & Unix
C++ users: Download BD Software's free STL Error Message
Decryptor at www.bdsoft.com/tools/stlfilt.html
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
Alexander Malkis wrote: typedef enum foo { A,B,C } foo;
.....
char* strs[C+1]={"Astr","Bstr","Cstr"};
NB: The following refers to C++. I don't know the answer in C.
Your approach almost certainly will work in this particular case.
However, it may not work in the general case. Enums are not guaranteed
to have any minimum number of bits, as long as they are wide enough to
hold all of their enumerators.
Here is a common alternative:
enum Foo { a, b, c, num_foo };
-Jeff
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
[F'up2 cut down --- should have been done by OP!]
In comp.lang.c.moderated Alexander Malkis wrote: Assume we have somewhere typedef enum foo { A,B,C } foo;
Is C+1 a constant expression?
Yes. What makes you suspect otherwise?
I want to write smth. like char* strs[C+1]={"Astr","Bstr","Cstr"};
You don't need C+1 to be a constant, for that. Actually, you don't
need C+1 at all:
char *strs[] = {"Astr", "Bstr", "Cstr"};
--
Hans-Bernhard Broeker (br*****@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
In <cl****************@plethora.net> Alexander Malkis <al******@LOESCHEDIESline.cs.uni-sb.de> writes: Assume we have somewhere typedef enum foo { A,B,C } foo;
Is C+1 a constant expression?
Yes.
[ I want to write smth. like char* strs[C+1]={"Astr","Bstr","Cstr"}; ]
What's wrong with:
char *strs[] = {"Astr", "Bstr", "Cstr"};
?
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
[ugh -- horribly cross-posted and no followup-to]
in comp.lang.c.moderated i read: Assume we have somewhere typedef enum foo { A,B,C } foo;
Is C+1 a constant expression?
yes.
--
a signature
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
Alexander Malkis schrieb: Is C+1 a constant expression?
Where do you want to find the answer? I see no fup2. And obviously
no-one so far recognized your crossposting anyway. Poor blind guys.
Fup2 ... hmmm ... where? ... let's see ... yes, that seems adequate.
Claus
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
Jeff Schwab wrote: Alexander Malkis wrote:
typedef enum foo { A,B,C } foo;
....
char* strs[C+1]={"Astr","Bstr","Cstr"}; NB: The following refers to C++. I don't know the answer in C.
Your approach almost certainly will work in this particular case. However, it may not work in the general case. Enums are not guaranteed to have any minimum number of bits, as long as they are wide enough to hold all of their enumerators.
Just for the record, an enum in C, unlike in C++, is always an int. And
the size enum foo doesn't matter here anyway.
Tor
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
Tor Husabø wrote: Jeff Schwab wrote:
Alexander Malkis wrote:
typedef enum foo { A,B,C } foo; ....
char* strs[C+1]={"Astr","Bstr","Cstr"};
NB: The following refers to C++. I don't know the answer in C.
Your approach almost certainly will work in this particular case. However, it may not work in the general case. Enums are not guaranteed to have any minimum number of bits, as long as they are wide enough to hold all of their enumerators.
Just for the record, an enum in C, unlike in C++, is always an int. And the size enum foo doesn't matter here anyway.
Yes, you're right. Of course, if A, B, and C were macros representing
expressions with large initializers, or if int's were only one bit
wide... :)
It is true, though, that the size of the array doesn't need to be
specified explicitly here anyway.
--
comp.lang.c.moderated - moderation address: cl**@plethora.net This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Chris Saunders |
last post by:
I have made a declaration like this:
private const Complex I = new Complex(0.0, 1.0);
When I try to build this I get the error:
The expression being assigned to...
|
by: devdatta_clc |
last post by:
Hi C experts
I've a bunch of questions.
Consider this simplified piece of code.
const int a = 10;
int main () {
static int b = a;
|
by: Andrzej 'Foxy' D. |
last post by:
Hi!
I cannot figure out, why is the following code incorrect:
const int array = { 1 };
const int var = 1;
template<int I>
struct Blah {};
|
by: lovecreatesbeauty |
last post by:
Both `K&R C, 2nd' and `C: A reference manual, 5th' introduce the
"hello, world" thing using the name "string-constant". But `ISO/IEC
9899:TC2' does not include this kind of thing in section `A.1.5...
|
by: Dan Smithers |
last post by:
What constitutes a constant-expression? I know that it is something that
can be determined at compile time.
I am trying to use template code and keep getting compiler errors
"error: cannot...
|
by: John Koleszar |
last post by:
Hi all,
I'm porting some code that provides compile-time assertions from one
compiler to another and ran across what I believe to be compliant code
that won't compile using the new compiler. Not...
|
by: Hendrik Schober |
last post by:
Hi,
this
#include <string>
class test {
typedef std::string::size_type size_type;
static const size_type x = std::string::npos;
};
doesn't compile using either VC9 ("expected constant...
|
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: Stefano Sabatini |
last post by:
Hi all, I'm encountering this while trying to implement a factory
singleton method to generate objects.
The singleton has a static map which binds a static creation function
defined in each...
|
by: PJ6 |
last post by:
Const factor As Double = Math.Sqrt(3) / 6
Error 1 Constant expression is required.
This looks like laziness to me. In SQL Server, functions are given a
distinction between ones that always...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |