This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

can anyone find this in the ANSI C standard

I am not asking what it will do, that is a simple experimnt that I can do myself. Does anyone have specific knowledge of whether the following for loop where WFLcnt is an unsigned char is specified in the ANSI C standard to run 0 or 256 times.

  for ( WFLcnt = 0 ; WFLcnt !=0 ; WFLcnt++)
  {
   .....
  }
YES, if WFLcnt was a short, the question is moot, but i need to use a char for speed reasons. in advance, thanks Erik

Parents
  • "if you tried to answer my question instead of trying to find fault with my example, maybe there could come something out of it."

    Here's your original question:

    "Does anyone have specific knowledge of whether the following for loop where WFLcnt is an unsigned char is specified in the ANSI C standard to run 0 or 256 times.

    for ( WFLcnt = 0 ; WFLcnt !=0 ; WFLcnt++)
    {
    .....
    }
    "

    Here's my original answer:

    "The simple answer to your question is that the ANSI standard guarantees that the loop will run zero times. Whether you use an unsigned char or a short is irrelevant."

    In what way does that not answer the question you asked?


    "but what the.... is wrong with the question. "what does the standard say about overflowing variables"."

    That's a completely different question. There was no mention of overflow in either your original question or the example you gave. How can I answer a question you didn't ask?

    The answer to your second, completely different question is that for unsigned integer types the standard guarantees that the increment will wrap from the largest representable value to the smallest. For signed integer types the behaviour is undefined.

Reply
  • "if you tried to answer my question instead of trying to find fault with my example, maybe there could come something out of it."

    Here's your original question:

    "Does anyone have specific knowledge of whether the following for loop where WFLcnt is an unsigned char is specified in the ANSI C standard to run 0 or 256 times.

    for ( WFLcnt = 0 ; WFLcnt !=0 ; WFLcnt++)
    {
    .....
    }
    "

    Here's my original answer:

    "The simple answer to your question is that the ANSI standard guarantees that the loop will run zero times. Whether you use an unsigned char or a short is irrelevant."

    In what way does that not answer the question you asked?


    "but what the.... is wrong with the question. "what does the standard say about overflowing variables"."

    That's a completely different question. There was no mention of overflow in either your original question or the example you gave. How can I answer a question you didn't ask?

    The answer to your second, completely different question is that for unsigned integer types the standard guarantees that the increment will wrap from the largest representable value to the smallest. For signed integer types the behaviour is undefined.

Children
No data