"C4127: conditional expression is constant" Huh?

This is a discussion on "C4127: conditional expression is constant" Huh? within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by Elysia It doesn't do that. Not in Visual Studio at the very least. Too bad for Visual ...

  1. #16
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Quote Originally Posted by Elysia View Post
    It doesn't do that. Not in Visual Studio at the very least.
    Too bad for Visual Studio then. Statements that have no effect are normally quite bad.

    But then this "fix" isn't really portable.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  2. #17
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    Quote Originally Posted by anon View Post
    Too bad for Visual Studio then. Statements that have no effect are normally quite bad.
    Are not. The compiler will ignore them anyway.
    And it's a great way to remove the "unreferenced" warning.
    I think it's a good thing.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    The compiler will ignore them anyway
    That's the point. In most contexts you do not write a code to be ignored by the compiler. So when such a code is encountered - it is very likely to be an error
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #19
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    Ah yes, but they do work fine for things such as suppressing warnings, if the compiler supports it. I think it is a good feature, anyway.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #20
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    I'm using following macro for unused function argumants - but I do not know if some compiler
    will complain
    (unused local vars I just remove or place inside proper #ifdefs)

    Code:
    #define UNUSED_ARG(_arg) if (_arg) {}
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  6. #21
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Wouldn't it be quite easy to do this?
    Code:
    void foo(int , int y) //first argument is unused
    {
        //use y
    }
    Last edited by anon; 03-13-2008 at 12:10 PM.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  7. #22
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    Yep, that's what I do for function arguments.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #23
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by anon View Post
    Wouldn't it be quite easy to do this?
    I write mostly in C
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  9. #24
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    I'll give you another example:
    Code:
    void func( char* str, int num )
    {
        ASSERT( num < 50 );
    ...  // num isn't used anywhere else.
    }
    I encountered some 3rd party code similar to this. Since they use the ASSERT() macro, num is used in Debug mode but not in Release mode. God only knows what the point is of this, but I didn't write it and I don't want to risk breaking anything, so the only ways of silencing the warning about unused parameter is either use a #pragma, or add num; to make the compiler shut up.

    #pragma statements (and warning numbers/messages) are different between compilers, so I chose num; instead.

  10. #25
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >Statements that have no effect are normally quite bad.
    Agreed.

  11. #26
    The larch
    Join Date
    May 2006
    Posts
    3,573
    To do VC++ justice, it seems that only expressions of type p; don't cause a warning. If there's an operator or such thrown into the mix, you get the "effectless statement" warning (e.g a + b; ).

    I could still imagine such a situation where a warning might draw attention to a problem:
    Code:
    //global
    int c;
    
    void foo()
    {
        int a, b; c; //one semicolon by mistake
        ...
    }
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  12. #27
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    I don't think I've ever done such a mistake...
    But then, if you tried to use c, you'd get an undeclared warning and it should be pretty obvious then that you have done a mistake there...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #28
    The larch
    Join Date
    May 2006
    Posts
    3,573
    I think I have made such mistakes (semicolon instead of comma), and in this example there is a global int c. Meaning the whole function will use this, instead of a local c that was supposed to shadow it.

    It is a contrived example, though...
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with making a Math Expression DLL
    By MindWorX in forum C Programming
    Replies: 19
    Last Post: 07-19-2007, 11:37 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. recursion error
    By cchallenged in forum C Programming
    Replies: 2
    Last Post: 12-18-2006, 08:15 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Expression Evaluator Contest
    By Stack Overflow in forum Contests Board
    Replies: 20
    Last Post: 03-29-2005, 09:34 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21