C variable retyping

From: Groups User (googlegroups_001_at_yahoo.com)
Date: 08/27/04


Date: 27 Aug 2004 10:19:57 -0700

C allows type casting in which a variable is converted from one type
to another.

Does C (whatever standard) allow the type of a variable to change,
within a statement, avoiding the conversion? And if so, provide an
example of how its done.

Example:
int a=23;
int b=34;
char c='a';
int * p_int=(int *) &c;

// type casting
// c is converted into type integer, then b is added.
(int) c + b;

//retypeing
(type int) c + b;
// similar action
*p_int + b

Ignoring alignment issues, storage size issues, etc., c is retyped to
an integer, no conversion is done, and c is used, within the
statement, as an integer, not a char.

Thanks



Relevant Pages

  • Re: Problem with linker
    ... but to have actually written a default constructor. ... such as overloading on int and pointer types. ... conversion of 0 to CString requires a user-defined conversion, ... acceleration operator *(distance d, time_squared t2); ...
    (microsoft.public.vc.mfc)
  • Re: Atoi keeps on failing.
    ... > int main ... in ] to effect this conversion: ... You could continue using 'atoi' but extract a 'char* from the string via: ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Function returning a char
    ... I was referring to int functions such as tolowerfrom the standard header ... representable as a char, the return value must have higher rank. ... If your compiler generates code to perform an unnecessary conversion, ...
    (comp.lang.c)
  • Re: Interesting list Validity (True/False)
    ... TypeError: int argument required ... If the gmpy writers are not allowing the conversion, ... it raises an OverflowError and the "%d" formatting ...
    (comp.lang.python)
  • Re: Type conversion question
    ... I know that C does some implicit type conversion like integer ... promotion and float to double. ... int main{ ... char cc = ii; ...
    (comp.lang.c)