CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    May 2002
    Location
    France, Toulouse
    Posts
    156

    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

  2. #2
    Join Date
    Jan 2000
    Location
    Dresden / Germany
    Posts
    322

    Question

    Hi,

    I don't know, what you want to do with that macro.
    Can you explain, what you want, please?

    Bye, Pryrates.

  3. #3
    Join Date
    May 2002
    Location
    France, Toulouse
    Posts
    156
    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

  4. #4
    Join Date
    Jan 2000
    Location
    Dresden / Germany
    Posts
    322
    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.

  5. #5
    Join Date
    May 2002
    Location
    France, Toulouse
    Posts
    156
    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

  6. #6
    Join Date
    Jan 2000
    Location
    Dresden / Germany
    Posts
    322
    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.

  7. #7
    Join Date
    May 2002
    Location
    France, Toulouse
    Posts
    156
    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

  8. #8
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470
    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
  •  





Click Here to Expand Forum to Full Width

Featured