-
July 9th, 2002, 08:13 AM
#1
case:__LINE__ problem
Hi
I have the folowing in my code:
#define crReturn(z) \
do {\
crLine=__LINE__; return (z); case __LINE__:;\
} while (0)
and when I call crReturn(z) in my program I get an error:
D:\SSH.C(707) : error C2051: case expression not constant
how can I solve this problem.
i use visual C++ 6.0
thank you
-
July 9th, 2002, 08:30 AM
#2
Hi,
I don't know, what you want to do with that macro.
Can you explain, what you want, please?
Bye, Pryrates.
-
July 9th, 2002, 08:33 AM
#3
Hi
I don't write this code but i need to use i.
I have a C and files and headers that I need to use but when
compiling i get that error.
and the code is too long and complexe and I have not the time to change it.
I think if i missed something in the settings...
thank you for help
khaldoun
-
July 9th, 2002, 08:45 AM
#4
Hi,
if you use the macro, the code will expanded to:
Code:
do {
crLine=__LINE__; return 0; case __LINE__:;
} while(0);
In my opinion, it is senseless. And incorrect, because you can use "case" only with "switch".
I would ask the author of the code, what he want to do.
Bye, Pryrates.
-
July 9th, 2002, 08:51 AM
#5
the code is the following:
#define crBegin1 static int crLine = 0;
#define crBegin2 switch(crLine) { case 0:;
#define crBegin crBegin1; crBegin2;
#define crFinish(z) } crLine = 0; return (z)
#define crFinishV } crLine = 0; return
#define crReturn(z) \
do {\
crLine=__LINE__; return (z); case __LINE__:;\
} while (0)
#define crReturnV \
do {\
crLine=__LINE__; return; case __LINE__:;\
} while (0)
and in the main() he do:
crBegin;
next_packet:
pktin.type = 0;
pktin.length = 0;
for (st->i = st->len = 0; st->i < 4; st->i++) {
while ((*datalen) == 0)
crReturn(4 - st->i);
the problem is in case:__LINE__: the compiler doesn't consider that __LINE__ is constant.
thank you for help
-
July 9th, 2002, 09:00 AM
#6
Hi,
I think, __LINE__ is not a constant for the the compiler.
I don't know, how you can change the code. Sorry, I have no idea.
Bye, Pryrates.
-
July 9th, 2002, 09:03 AM
#7
thank you because you tried to help.
I solved the problem, it was a bug in visual C++, I just changed the compiler setting from "Program Database for Edit and Continue' to "Program Database" and the code works very well
thank you again
khaldoun
-
July 9th, 2002, 09:39 AM
#8
I still think you need to find the original author and reprogram him with a large axe. That sort of trickery crap is among the worst programming sins around. There is no need for it and it should be stamped out immediately.
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there.
-- Gordon Bell
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|