c - sizeof() operator in if-statement -


#include <stdio.h> main() {     if (sizeof(int) > -1)         printf("true");     else         printf("false"); } 

it prints false. why doesn't sizeof() return value in if?

  1. sizeof not function, it's operator. parentheses not part of operator's name.
  2. it's failing because value generated has unsigned type size_t, causes "the usual arithmetic conversions" in -1 converted unsigned, in case it's large number.

basically you're comparing 4 > 0xffffffffu, or close @ least. see question details.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -