473,385 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

switch expression not integral ???

I am getting the following error during compiling:

'switch expression not integral'

I am new to the switch command - here is a snip of my code where I have
used this.. .. what is the problem here? Thanks!

------------- snip --------------------------

for (ii = 0; ii < n; ii++)
{
if (!UF_OBJ_ask_name(members[ii], obj_name))
{
sprintf(msg,"\nObject #%d has an object tag = %d and is named
%s,",ii,members[ii],obj_name);
WRITE(msg);

UF_CALL(UF_DRF_ask_draft_aid_text_info(members[ii], &nn,
&text_info));

for (iii=0; iii<nn; iii++)
{
WRITE3F(text_info[iii].origin);
for (jj=0; jj<text_info[iii].num_lines; jj++)
{
sprintf(msg, " %s\n", text_info[iii].text[jj].string);
UF_UI_write_listing_window( msg );
}
}
UF_CALL(UF_DRF_free_text(nn, &text_info));
switch (obj_name)
{
case "NOTE TEXT CP SL":
uc5566(members[ii], 1, 6, "J");
break;
case "NOTE TEXT CP COC":
uc5566(members[ii], 1, 6, "O");
break;
case "NOTE TEXT CP PQP":
uc5566(members[ii], 1, 6, "H");
break;
case "NOTE TEXT CP FRD":
uc5566(members[ii], 1, 6, "N);
break;
case "NOTE TEXT CP SC":
uc5566(members[ii], 1, 6, "P);
break;
default:
break;
}

}
}

Nov 14 '05 #1
6 18171
ba*************@yahoo.com wrote:
I am getting the following error during compiling:

'switch expression not integral'
The argument to switch must be integral. It can't be a floating point
value, a structure or a pointer (including char pointers aka strings).
I am new to the switch command - here is a snip of my code where I have
used this.. .. what is the problem here? Thanks!


Please reduce your examples to the smallest piece of code that demonstrates
your problem.

Uli

Nov 14 '05 #2
ba*************@yahoo.com wrote:
I am getting the following error during compiling:

'switch expression not integral'

I am new to the switch command - here is a snip of my code where I have
used this.. .. what is the problem here? Thanks!
Well, switch can only be applied to integer data types, i.e
char, (un)signed char, (un)signed short, (un)signed int,
(un)signed long (, size_t, ..., C99: (un)signed long long,
the int*_t types, ptrdiff_t, ...) but not to a pointer
-- at least I guess that obj_name is either of type char *
or of type array of char.

------------- snip --------------------------

for (ii = 0; ii < n; ii++)
{
if (!UF_OBJ_ask_name(members[ii], obj_name))
{
sprintf(msg,"\nObject #%d has an object tag = %d and is named
%s,",ii,members[ii],obj_name);
WRITE(msg);

UF_CALL(UF_DRF_ask_draft_aid_text_info(members[ii], &nn,
&text_info));

for (iii=0; iii<nn; iii++)
{
WRITE3F(text_info[iii].origin);
for (jj=0; jj<text_info[iii].num_lines; jj++)
{
sprintf(msg, " %s\n", text_info[iii].text[jj].string);
UF_UI_write_listing_window( msg );
}
}
UF_CALL(UF_DRF_free_text(nn, &text_info));
switch (obj_name)
{
case "NOTE TEXT CP SL":
uc5566(members[ii], 1, 6, "J");
break;
case "NOTE TEXT CP COC":
uc5566(members[ii], 1, 6, "O");
break;
case "NOTE TEXT CP PQP":
uc5566(members[ii], 1, 6, "H");
break;
case "NOTE TEXT CP FRD":
uc5566(members[ii], 1, 6, "N);
break;
case "NOTE TEXT CP SC":
uc5566(members[ii], 1, 6, "P);
break;
default:
break;
}

}
}


A workaround: Apply switch to the first significant
character...
switch (obj_name[13]) {
case 'S':
/* Either SC or SL */
break;
case 'C':
....
}

Two things for future requests:
* Please give us a minimal example which we can directly
feed to a compiler.
* Indent your code. Not with tabs but with spaces.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 14 '05 #3
ba*************@yahoo.com wrote:
I am getting the following error during compiling:

'switch expression not integral'

I am new to the switch command - here is a snip of my code where I have
used this.. .. what is the problem here? Thanks!


The problem here is just what the compiler said: 'switch expression not
integral'. In C language switch argument as well as case labels must be
integral expressions. You seem to be trying to use pointer expressions
('char*') instead. This will not work. If you want to build a multiway
dispatcher based on string argument, one way to go is to use 'if' ladder

if (strcmp(obj_name, "NOTE TEXT CP SL") == 0)
uc5566(members[ii], 1, 6, "J");
else if (strcmp(obj_name, "NOTE TEXT CP COC") == 0)
uc5566(members[ii], 1, 6, "O");
else if (strcmp(obj_name, "NOTE TEXT CP PQP") == 0)
uc5566(members[ii], 1, 6, "H");
/* ... and so on */

Switch is not applicable here. At least, not immediately applicable.

--
Best regards,
Andrey Tarasevich
Nov 14 '05 #4
Thanks for all the replies - I did not realize it was only a test for
integers - didn't realize that integral meant integer actually.

I will post a more usable snippet in the future...

Thanks again..

John

Nov 14 '05 #5

<ba*************@yahoo.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Thanks for all the replies - I did not realize it was only a test for
integers
Actually, the type of the 'case' expression is even more restricted
than that. The expression must be a constant integer expression.

int main()
{
int x = 42;
int y = 99;

switch(x)
{
case y: /* ERROR: not constant expression */
break;
case 99: /* OK: constant expression */
break;
default:
break;
}

return 0;
}
- didn't realize that integral meant integer actually.


Now you know. :-)

-Mike
Nov 14 '05 #6
In article <11*********************@f14g2000cwb.googlegroups. com>,
ba*************@yahoo.com says...
Thanks for all the replies - I did not realize it was only a test for
integers - didn't realize that integral meant integer actually.


Where you thinking it meant the area under the switch curve? :-)
Nov 14 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Scott C. Reynolds | last post by:
In VB6 you could do a SELECT CASE that would evaluate each case for truth and execute those statements, such as: SELECT CASE True case x > y: dosomestuff() case x = 5: dosomestuff() case y >...
8
by: Sivas | last post by:
Hi, Can anyone tell me why this does not work: --------------------------------------------- float b = 2.51F; switch(b) {
7
by: Tim Cowan | last post by:
Hi I was wondering if someone could help me change these ifs to a switch statement. I tried but I can't make it work. Thanks Tim Code below: protected void...
27
by: Yuriy Solodkyy | last post by:
Hi VS 2005 beta 2 successfully compiles the following: using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program {
5
by: nobody | last post by:
With Visual C++ 2005 beta 2, I get the below compling error for the following code. I think this error is not acceptable to me because int::typeid is a constant and is known to compiler when...
1
by: Neelesh Bodas | last post by:
Can somebody please explain the fine difference between these two clauses of the standard: 4.5 (Integral promotions) 4. An rvalue of type bool can be converted to an rvalue of type int, with...
18
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp...
56
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
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...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
jinu1996
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.