empty control statement (?)

This is a discussion on empty control statement (?) within the C++ Programming forums, part of the General Programming Boards category; I have a program. Here is the code that is giving me a warning: Code: void Sensor::SetSensorState(char *cState) { char ...

  1. #1
    Shadow12345
    Guest

    empty control statement (?)

    I have a program. Here is the code that is giving me a warning:
    Code:
    void Sensor::SetSensorState(char *cState) {
    	char On[] = "On";
    	char Off[] = "Off";
    	
    	if(!strcmp(cState, On));
    		strncpy(State, cState, 50);*
    	if(!strcmp(cState, Off));
    		strncpy(State, cState, 50);*
    	
    }
    On the lines with the '*' I am getting a warning that says :

    warning C4390: ';' : empty controlled statement found; is this the intent?

    as I said this is a warning, not an error, so my program compiles and runs (up to this point).
    what should I change about the code above?

    [edit]
    nevermind....duh...that was a lame mistake...

  2. #2
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Remove the ';' after the if.

  3. #3
    Shadow12345
    Guest
    are you making fun of me?

  4. #4
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    No he isn't, if statements dont have ;'s at the end like other control structures.

    while( condition ) //no ;
    {

    }

    for( initialise; end condition; increment ) //no ;
    {

    }

    if( condition ) //no ;
    {

    }

  5. #5
    Unregistered
    Guest
    It is perfect legally to put ";" after if, thenyou got a warning.

    what are you trying to do though?

    what do I know?

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by Unregistered
    It is perfect legally to put ";" after if, thenyou got a warning.

    what are you trying to do though?

    what do I know?
    Of course its perfectly legal, but just because something is legal doesn't mean that is always what we want. For instance these two statements are the same and do nothing.

    Code:
    // Statement 1
    if( bValue == true );
    
    // Statement 2
    if( bValue == true )
      ;
    Both do nothing because there are no brackets, it will only execute the first command after the if statement, which is a nothing, just the semi-colon. That's why if you do this on a for loop it just runs the entire loop without going inside of it.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Usefulness of the "else if" statement
    By gn17 in forum C Programming
    Replies: 7
    Last Post: 08-12-2007, 06:19 AM
  2. creating an activex control
    By Benzakhar in forum Windows Programming
    Replies: 9
    Last Post: 12-29-2003, 06:32 PM
  3. Updating a list control
    By MPSoutine in forum Windows Programming
    Replies: 2
    Last Post: 12-05-2003, 02:03 AM
  4. Problems with my edit control...
    By tyouk in forum Windows Programming
    Replies: 19
    Last Post: 10-19-2003, 01:36 AM
  5. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 04:49 PM

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