Hi! I'm pretty new to C and I'am getting an error from GCC 4.0 with the
following function:
unsigned int search_for_clo_tag (const unsigned char *array, const
unsigned int array_element) {
unsigned char clo_tag;
unsigned int i;
unsigned char ope_tags[1];
switch (*(array + array_element)) {
case '(':
clo_tag = ')';
*ope_tags = '[';
*(ope_tags + 1) = '{';
break;
case '[':
clo_tag = ']';
*ope_tags = '(';
*(ope_tags + 1) = '{';
break;
case '{':
clo_tag = '}';
*ope_tags = '(';
*(ope_tags + 1) = '[';
break;
}
for (i = 1; *(array + array_element + i) != '\0'; i++)
switch (*(array + array_element + i)) {
case *(array + array_element): case *ope_tags: case *(ope_tags + 1):
if (!must_be_ignored (array, array_element + i))
i = search_for_clo_tag (array, array_element + i) - array_element;
break;
case clo_tag:
if (!must_be_ignored (array, array_element + i))
return array_element + i;
break;
}
}
The error is: "case label does not reduce to an integer constant" and
its related to the second switch. I don't understand why this happen,
since chars are integers, right?
Well, hope you can help me. Thank you and good luck!
PS: Sorry my English. I'am from Argentina, :P 11 17689
adelfino wrote:
[...] switch (*(array + array_element + i)) {
case *(array + array_element): case *ope_tags: case *(ope_tags + 1):
none of these cases are integer constants
[...]
case clo_tag:
nor is this one
The error is: "case label does not reduce to an integer constant" and its related to the second switch. I don't understand why this happen, since chars are integers, right?
So what? variables are not constants.
Oh, I get it.
Now I will have to figure out how to do something like that without
variables.
Thank you Martin!
adelfino wrote: Oh, I get it. Now I will have to figure out how to do something like that without variables.
Thank you Martin!
I prefer the 'else if' model to the switch cases. Something like this..
if (expr1)
do1();
else if (expr2)
do2();
else if (expr3)
do3();
else
do0(); /* when all else fails */
--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
adelfino wrote: Hi! I'm pretty new to C and I'am getting an error from GCC 4.0 with the following function:
Another bug unrelated to the switch problem:
unsigned char ope_tags[1];
[ ... ]
*ope_tags = '[';
*(ope_tags + 1) = '{';
You are causing undefined behavior here; for this assignment to work,
ope_tags needs to have at least two elements.
Christian
But, doesn't ope_tags have two elements?
ope_tags[0] and ope_tags[1]?
Anyway, I split them into two separate unsigned chars, ;)
On Wed, 06 Jul 2005 07:50:40 -0700, adelfino wrote: On Tue, 05 Jul 2005 10:07:44 +0200, Christian Kandeler wrote: adelfino wrote:
Hi! I'm pretty new to C and I'am getting an error from GCC 4.0 with the following function:
Another bug unrelated to the switch problem:
unsigned char ope_tags[1];
[ ... ]
*ope_tags = '[';
*(ope_tags + 1) = '{';
You are causing undefined behavior here; for this assignment to work, ope_tags needs to have at least two elements.
But, doesn't ope_tags have two elements?
ope_tags[0] and ope_tags[1]?
Anyway, I split them into two separate unsigned chars, ;)
You didn't quote the message you were replying to - I've added it above.
In answer to your question, no, it doesn't. You declared it with size of
one so it only has one element. You are confusing the declaration of the
array size with its indexing. Indexing is zero-based, so you are right
that you can index ope_tags[0]. Declaring size, though, is not zero-based
so you specify the actual size you require. So if you want to properly
access a second location (ope_tags[1] or rather as you have written it,
the equivalent *(ope_tags + 1)) then you need to declare the array of size
at least 2:
unsigned char ope_tags[2];
In general if you want to index an array at [n] you need to declare the
array to be of size at least n+1.
adelfino wrote: But, doesn't ope_tags have two elements?
ope_tags[0] and ope_tags[1]?
Anyway, I split them into two separate unsigned chars, ;)
How can anyone tell? You don't show any code, especially no
declaration for the "ope_tags" entity.
--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
@Netocrat
OK, now I get it, ;)
@CBFalconer
Yes, I show the code, in my first post:
unsigned char ope_tags[1];
@*
Thanks, and good luck!
adelfino wrote: @Netocrat
OK, now I get it, ;)
No you don't. You still are failing to quote adequate context.
See my sig below.
--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Sorry, I meant I understood what Netocrat said about indexing and
declaring.
CBFalconer wrote: adelfino wrote: @Netocrat
OK, now I get it, ;)
No you don't. You still are failing to quote adequate context. See my sig below.
-- "If you want to post a followup via groups.google.com, don't use the broken "Reply" link at the bottom of the article. Click on "show options" at the top of the article, then click on the "Reply" at the bottom of the article headers." - Keith Thompson
adelfino wrote: CBFalconer wrote: adelfino wrote: @Netocrat
OK, now I get it, ;)
No you don't. You still are failing to quote adequate context. See my sig below.
-- "If you want to post a followup via groups.google.com, don't use the broken "Reply" link at the bottom of the article. Click on "show options" at the top of the article, then click on the "Reply" at the bottom of the article headers." - Keith Thompson
Sorry, I meant I understood what Netocrat said about indexing and declaring.
But evidently you did *not* understand what Mr. Falconer said about
top posting...
--
+----------------------------------------------------------------+
| Charles and Francis Richmond It is moral cowardice to leave |
| undone what one perceives right |
| richmond at plano dot net to do. -- Confucius |
+----------------------------------------------------------------+ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: JKop |
last post by:
g++ test.cpp -ansi -pedantic -o test.exe
test.cpp: In function `int main()':
test.cpp:22: case label does not reduce to an integer constant
Why won't "operator unsigned int() const" do its job...
|
by: Martin Magnusson |
last post by:
I'm using enums as case labels throughout my code, and that works fine
in gcc 3.3.4. However, when compiling it with the compiler that ships
with Dev-C++ 4.9.8.0, I get the error "case label does...
|
by: SysSpider |
last post by:
Hi again,
This is my problem: when i try to compile the code that contains the
function below, i get this:
--
gcc:21: error: case label does not reduce to an integer constant
gcc:24: error:...
|
by: qianz99 |
last post by:
Hello I define a sequence of const
typedef struct
{
int year;
int month;
}birth
const birth a={1990,1};
const birth b={1990,2};
......
|
by: quakewang |
last post by:
hi,
I have define in a head file like this:
#define GLUT_BITMAP_9_BY_15 ((void*)2)
#define GLUT_BITMAP_8_BY_13 ((void*)3)
#define GLUT_BITMAP_TIMES_ROMAN_10 ...
|
by: Rex Mottram |
last post by:
Can anyone explain this?
% cat t.c
#include <stdio.h>
#define FIRST "first"
#define SECOND "second"
int
main(int argc, char *argv)
|
by: Harry2o |
last post by:
I stumbled upon the gcc error "case label does not reduce to an integer constant" when trying to use a const int variable in a case statement.
Basically what is discussed in this thread:...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
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...
| |