COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### why error C2051?

• Email
• Follow

const int c=9;

void main()
{
int a=9;
switch (a)
{
case c:
a=c+1;
break;
}
}
-----------
compile result:
c.c(8) : error C2051: case expression not constant
-----------
But [c] is a const int....why?


 0
Reply zhangchunlin (3) 11/17/2006 7:21:47 AM

See related articles to this posting

clino said:

> const int c=9;
>
> void main()

int main(void)

> {
> int a=9;
> switch (a)
> {
> case c:
> a=c+1;
> break;
> }
> }
> -----------
> compile result:
> c.c(8) : error C2051: case expression not constant
> -----------
> But [c] is a const int....why?

It's a const int all right, but it isn't a constant integer expression,
which is what you need in a case expression.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not

 0
Reply invalid171 (7011) 11/17/2006 7:54:59 AM

"clino" <zhangchunlin@gmail.com> wrote:

> const int c=9;
>
> void main()

<http://c-faq.com/ansi/maindecl.html>
<http://c-faq.com/ansi/voidmain.html>
<http://c-faq.com/ansi/voidmain3.html>
<http://c-faq.com/ansi/voidmainbooks.html>

> {
> 	int a=9;
> 	switch (a)
> 	{
> 	case c:
> 		a=c+1;
> 		break;
> 	}
> }
> -----------
> compile result:
> c.c(8) : error C2051: case expression not constant
> -----------
> But [c] is a const int....why?

<http://c-faq.com/cpp/constvsdefine.html>
<http://c-faq.com/ansi/constasconst.html>

HTH; HAND; RTFFAQ.

Richard

 0
Reply rlb (4118) 11/17/2006 8:08:16 AM

very clearly~
Thank u very much~

On 11=D4=C217=C8=D5, =CF=C2=CE=E74=CA=B108=B7=D6, r...@hoekstra-uitgeverij.=
nl (Richard
Bos) wrote:
> "clino" <zhangchun...@gmail.com> wrote:
> > const int c=3D9;
>
> > void main()<http://c-faq.com/ansi/maindecl.html>
> <http://c-faq.com/ansi/voidmain.html>
> <http://c-faq.com/ansi/voidmain3.html>
> <http://c-faq.com/ansi/voidmainbooks.html>
>
> > {
> >    int a=3D9;
> >    switch (a)
> >    {
> >    case c:
> >            a=3Dc+1;
> >            break;
> >    }
> > }
> > -----------
> > compile result:
> > c.c(8) : error C2051: case expression not constant
> > -----------
> > But [c] is a const int....why?<http://c-faq.com/cpp/constvsdefine.html>
> <http://c-faq.com/ansi/constasconst.html>
>=20
> HTH; HAND; RTFFAQ.
>=20
> Richard


 0
Reply zhangchunlin (3) 11/17/2006 8:34:01 AM

3 Replies
51 Views

Similar Articles

12/12/2013 6:07:57 PM
page loaded in 40625 ms. (0)

Similar Artilces:

@@Error not catching error.
Hi all, I want to catch error in stored procedure and return error message. I want to catch error 'Syntax error converting the varchar value 'a' to a column of data type int.' Means error occuring if i enter wrong value. Say suppose i have statment like select * from emp where rowid = 'a' PRINT @@ERROR print 'reach' here rowid is integer value so i am getting above mention error. So what i am expecting is it should print error and then print 'reach' which is not happening. can anyone tell me reason behind this and how to overcome this problem. than...

Robust error handling, an error while handling another error
I've been having this discussion a lot with my colleagues at work. A buffered file writer is the classic example. #include <fstream> int main() { std::ofstream fout("foo.txt"); if ( ! fout) return 1; //write important data to file //let the destructor implicitly close the file handle } The ofstream destructor will call flush then free the file handle, return it to the operating system. However, flush can fail. The disk can be full, for example. When flush fails, it sets a state flag, but there is no opportunity for the user to examine this state fl...

Re: ERROR: Error fetching from cursor. ORACLE error is ORA-01555: #3
Consider first fetching the subset of DW_CDR_ACCOUNT_DAY that you want w/a pass-through query & then running through it in a datastep. Something like: Proc sql ; connect to oracle as ora (blah blah blah) ; create table gnu as select * from connection to ora (select day accnt_id record_type record_subtype paid_mou bonus_mou cust_type COS from DW_CDR_ACCOUNT_DAY where day <= to_date(&orastartdate) and cust_type='Consumer' and record_type in ('VOICE','SMS','XTRAS') and COS in (10,20,30,40,60) ) ; disconnect from ...

Error reporting (for syntactic errors)
This may be a quite basic question. I am contemplating writing a compiler for a language similar to java, though with some innovative (hah!) features added, etc etc. I started out with regular BNF, but have eliminated left recursion from the grammar through allowing the grammar to directly support lists with separators. I use no tools, all is written from scratch, and so can create new grammar constructs as I want. The grammar is supposed to be (mostly) context free, but as the grammar is implemented directly as java code, each production being a class, which at the same time is a node in the...

Error: missing ) in parenthetical error
Hi, Trying the following ... function getCurrentVal(poValue) { var lcCurrentVal = 0; if (isNaN(parseInt(poValue))) { var loValue = poValue.toUpperCase(); if (loValue == "/") { lcCurrentVal = "/"; } if (loValue == "X") ( lcCurrentVal = "X"; { } else { lcCurrentVal = parseInt(poValue); } if(lcCurrentVal) { return lcCurrentVal; } } and am getting the error Error: missing ) in parenthetical Line: 189, Column: 23 Source Code: lcCurrentVal = "X"; I can't for the life of me figure it out. If i comment this line out it works fine (but then t...

Error: Errors occurred
Hi, Can any one help me out or explain the procedure to eliminate the error mentioned below while using the Generate code only via Configuration Parameters for the Target TI6000 DM6437. *********************************************************** Error building Real-Time Workshop target for block diagram 'EdgeDetection'. MATLAB error message: Error using ==> tlc_new Error: Errors occurred - aborting. *********************************************************** The Model is build without any errors and when the execution of the model starts there are no errors, b...

Error
Hi All, I created a virtual directory VD for the physical directory C:\XYZ\ABC\. on a machine 10.10.9.9 The physical directory has got a file timer.exe and i am trying to access this from my client m/c. I created a hyperlink and the link rightly takes me to that file, the status bar shows that. like http://10.10.9.9/VD/timer.exe. when i download that file an error is thrown error. CGI Error The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are: Can someone help me out in rectifying the same. Regards Venkat PS: The apps are ...

error
after compiling and wrting the design i am getting an error as follows Warning: There is a data discrepancy between synopsys database and the output file. (VHDL-286) what cud be the reason ? thanks Hi, Provide more details as to: Is this simulation or synthesis? Which tool? As this is a Warning, what happens after this? Are you still able to go thro' the flow? Ajeetha, CVC www.noveldv.com i am able to go ahead i am sythesizing a simple vhdl adder I believe the error code VHDL-286 is documented in their docs, you may get lucky if you look in that. Ajeetha, CVC www.noveldv.c...

E2900 error on boot: TL = 1, TT = 32. ERROR: Data Access Error -- Help??
Can someone help decipher this error below? Had Sun CE install 32Gb memory into 2 system boards (64Gb total), and now we are getting this error. We tried powering it back up with each system board individually, and get same error no matter which board is in, or both. So we're pretty sure it's not a single dimm that is the problem Sun Fire E2900 OpenFirmware version 5.19.4 (01/19/06 18:06) Copyright 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. SmartFirmware, Copyright (C) 1996-2001. All rights reserved. 32768 MB memory installed, TL = 1, TT = 32....

E2900 error on boot: TL = 1, TT = 32. ERROR: Data Access Error -- Help?? #2
Can someone help decipher this error below? Had Sun CE install 32Gb memory into 2 system boards (64Gb total), and now we are getting this error. We tried powering it back up with each system board individually, and get same error no matter which board is in, or both. So we're pretty sure it's not a single dimm that is the problem Sun Fire E2900 OpenFirmware version 5.19.4 (01/19/06 18:06) Copyright 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. SmartFirmware, Copyright (C) 1996-2001. All rights reserved. 32768 MB memory installed, TL = 1, TT = 3...

ODBC Error: SQLSTATE = S1000, Native error code = -4977 The data buffer parameter is too short(Btrieve Error 22)
HI all, I am trying to insert a new record into a table and got the following error message ODBC Error: SQLSTATE = S1000, Native error code = -4977 The data buffer parameter is too short(Btrieve Error 22) Here is the query I am using. insert into amgr_user_fields_tbl values ('123456789012345678901234',0,38,0,0, '2003-11-01',0.0, '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890', '123456789012','2003-12-10','16:18:13','1234') Here is the table defination create...

transform
Hi, I get a compiler error when trying to use std::transform to iteratate/modify a list. If I write the same code by hand, it compiles fine. Am I misusing transform, or is this a compiler bug? The types involved are complex templates, but I don't think this should have any bearing on things. ------------------------------- const UserIFSeq& uList; UserIFSeq::const_iterator i; UserISeq users; // // Compiles Fine. // for (i = uList.begin(); i != uList.end(); i++) users.push_back(UserIPrx::uncheckedCast(*i)); // // Produces Error. // std::transform(uList.begin(), uList...

Mapping error codes to error messages
I need to make an error handling framework to be used by C++ applications running on HP-UX. In this, the application error codes can be mapped to pre-defined error messages. The framework would have C++ exception classes for error information propagation. I however have no clue on how to map the error codes to the messages, and efficiently access the messages through a simple mapping class or function. I know this is not exactly a UNIX question that we are discussing, but is anybody aware of any implementation techniques. Should it necessarily be a static array indexed by error codes or some r...

chemmacros, exp13.sty error error
Hi, I'm trying to write chemistry with oxidation numbers and if I google correctly chemmacros appear to be a good way to do this. But when I try to use it I get complaines about exp13.sty, about which I can find nothing useful. Code: \documentclass[a4paper,12pt]{article} \usepackage[version=3]{mhchem} \usepackage{chemmacros} \begin{document} \ce{\ox{1,H}} \end{document} And the error message is: ! LaTeX Error: File `exp13.sty' not found. Any suggestions? Par -- Par usenet@hunter-gatherer.org What was it they were saying about arn...

CGIWrap error: exec format error
This message usually indicates there is a problem with the script itself. Often this indicates either that the #! line of the script is incorrect, or the script was uploaded in binary mode instead of ascii mode. Check to make sure that the script does not have control-M's at the end of every line. That will prevent it from executing. An easy fix that takes care of this most of the time is to put '#!/.../perl --' instead of '#!/.../perl' on the first line of the script. This is typically a problem if the script was edited or uploaded from a DOS/Windows/Macintosh station to ...

ERROR:MDT
Hi, I start to work on FPGA Embedded system. I am trying to port the MonstaVista Linux on the system. First I built the system with EDK, the option for my system is: XUPV2P: powerPC 405 300MHz Bus 100MHz RS232_Uart_1 OPB UART 1655 (interrupt) Ethernet_MAC OPB ETHERNET (interrupt) SysACE_Compact Flash (interrupt) DDR_512MB I continue to work on software platform which is: Linux_mv131 version 1.01.b MEM_SIZE 0x10000000 PLB_CLOCK_FREQ_HZ 100000000 (100 MHz) Connected_periphs RS232_Uart_1, Ethernet_MAC, SysACE_CompactFlash, opb_intc_0 After generate the bitstream, then Generate Librari...

Error with script
Hi I'm been having this error nad can't seem to locate the source of the problem. I though the the error was the variables but even after isolating them, the error message: <<The server encountered an internal error or misconfiguration and was unable to complete your request.>> Still shows up. Does any have any idea what the cause is. Any help would be appreciated. HTML FILE________________________________________________________ <!-- ** INFORMATION ON THE PAGE **************************** Page name _________________ : PY_iPass.html Version ___________________ : 1.2...

what is the error
//a single link list,the nodes contain an integer value called value void handler::delete(){ int del; cout<<"which number do u want to delete"<<endl; cin>>del; node *previous;//always behind the sth node for(node *sth=head;sth!=NULL;sth=sth->next){ if(sth->value==del) { if(sth==head) { node *deleted=head; head=head->next; delete deleted; } else { node *deleted=sth; previous->next=deleted->next; delete deleted; } previous=sth; } } } jw wrote: > //a single link list,the nodes contain an integer value ...

Error...
Hi I try to make a vpn tunnel site to site with pdm and i have some error crypto map outside_map 220 set peer xx.xx.xx.xx WARNING:This crypto map is incomplete to remedy the situation add a peer and a valid access-list to this crypto map. what's is wrong.. regards Tomek W. wrote: > Hi > I try to make a vpn tunnel site to site with pdm > and i have some error > crypto map outside_map 220 set peer xx.xx.xx.xx > WARNING:This crypto map is incomplete > to remedy the situation add a peer and a valid access-list to this crypto > map. It's only a warn just add...

error,again
tentaively, got: create #table(a,b,c,d) insert into #table select A,B,C,D from s,t,x,y,z where y.price > 20 select *, (select max(D) from (select distinct top 2 with ties from #temp v where v.B=W.B and v.C = W.c), (select min(D) from (select distinct top 2 with ties from #temp v where v.B=W.B and v.C = W.c) from #temp w drop Table #temp This works, but if y.price > 20 condition is not met, unsupported error message gets produced within crystal report. i expected blank field report instead in this case, included If exists around the select statement , still same error. BTW, is ther...