Re: Code Comprehension



ena8t8si@xxxxxxxxx writes:

Pascal Bourguignon wrote:
[...]
I know perfectly well that _in_ _C_, the type
char is a subtype of the type int.

You're confused. First, your statement is wrong;
second, it has nothing to do with the meaning of
'\0', which C defines to be of type int, and not of
type char. Read the ISO C Standard.

If you don't want to understand, just tell me, I won't insist.

When you have characters, use '\0' which explictely says Hello! I'm a character.
When you have integers, use 0 which explicitely says Hi! I'm an integer.
When you have pointers, use NULL which explicitely says See! I'm a pointer.
When you have booleans, use FALSE, false, NO, or any such properly
defined constant, which explicitely says Hey! I'm a boolean!

But if you want your code to be readable don't be so dumb to write
things like:

{
char ch=0;
int i=NULL;
void* p=NO;
bool b='\0';
}

The fact that the compiler generates the same code is irrelevant!


--
__Pascal Bourguignon__ http://www.informatimago.com/

CAUTION: The mass of this product contains the energy equivalent of
85 million tons of TNT per net ounce of weight.
.



Relevant Pages

  • Re: sizeof operator
    ... fit in a char. ... those for other integer literals. ... have representable in an int are of type int, ... nothing special about characters, they are just integer types holding ...
    (comp.lang.c)
  • Re: need for an extra variable.
    ... is like getchar(), and that s is an array of char). ... getch() returns a result of type int. ... there's the additional problem that the conversion from int ...
    (comp.lang.c)
  • Re: Ex 7-5
    ... value in addition to the full character set. ... The value returned by getchar() is definitely of type int. ... That value might or might not be within the range of type char (i.e., ...
    (comp.lang.c)
  • Re: to calculate bitsize of a byte
    ... Not if UCHAR_MAX equals INT_MAX, ... because you can keep left-shifting the unsigned char and the ... behavior of an unsigned type on "overflow" is perfectly well-defined ... You're assuming that the right-hand operand is of type int. ...
    (comp.lang.c)
  • Re: Return array of ponters?
    ... bjrnove wrote: ... > You shouldn't work with an array of pointers like that. ... > a pointer to a char* whitch will give you the result you want. ... > /* main always has the type int and if no arguments you should always ...
    (comp.lang.c)