S
sophia.agnes
Hi ,
I was going through peter van der linden's book Expert C programming,
in this book there is a section named "How and why to cast"
the author then says as follows
(float) 3 - it's a type conversion and the actual bits change.
if you say (float) 3.0 it is a type disambiguation,and the compiler
can plant the correct bits in the first place.some people say that
casts are so named because they help something broken to limp along.
what exactly is this type disambiguation...????
i have n't seen any casts like (float) 3.0; in use (may be due to my
limited experience). how will it help the compiler to plant the
correct bits????
Then the author says that as an impratical example ,you can create a
pointer to ,for example printf(), with
extern int printf(const char*,...);
voif *f = (void *) printf;
you can then call printf through a properly cast pointer, in this
manner:
(*(int(*)(const char*,...))f)("Bite my shorts. Also my chars and ints
\n");
now void *f = (void *) printf; why this cast is required....????
^^^^^^
why the author says that above example is impractical...???
why is it because library functions are not meant to be called via
void pointer.....?????
for explanation of above issues i went to Richard heathfields site:
http://www.cpax.org.uk/prg/writings/casting.php
there i found nothing mentioned about type disambiguation..
but i found more complex example such as this
(int)((int (*)(const char *, ...))
printf((const char *)"%3.0f %6.1f\n",
(float)fahr, (float)celsius));
what exactly does this statement does...???
is it just simple printf such as this....
printf("%3.0f %6.1f\n",fahr, celsius);
why all these redundant casts such as
1)(const char *)"%3.0f %6.1f\n"
2)(int)((int (*)(const char *, ...))
I was going through peter van der linden's book Expert C programming,
in this book there is a section named "How and why to cast"
the author then says as follows
(float) 3 - it's a type conversion and the actual bits change.
if you say (float) 3.0 it is a type disambiguation,and the compiler
can plant the correct bits in the first place.some people say that
casts are so named because they help something broken to limp along.
what exactly is this type disambiguation...????
i have n't seen any casts like (float) 3.0; in use (may be due to my
limited experience). how will it help the compiler to plant the
correct bits????
Then the author says that as an impratical example ,you can create a
pointer to ,for example printf(), with
extern int printf(const char*,...);
voif *f = (void *) printf;
you can then call printf through a properly cast pointer, in this
manner:
(*(int(*)(const char*,...))f)("Bite my shorts. Also my chars and ints
\n");
now void *f = (void *) printf; why this cast is required....????
^^^^^^
why the author says that above example is impractical...???
why is it because library functions are not meant to be called via
void pointer.....?????
for explanation of above issues i went to Richard heathfields site:
http://www.cpax.org.uk/prg/writings/casting.php
there i found nothing mentioned about type disambiguation..
but i found more complex example such as this
(int)((int (*)(const char *, ...))
printf((const char *)"%3.0f %6.1f\n",
(float)fahr, (float)celsius));
what exactly does this statement does...???
is it just simple printf such as this....
printf("%3.0f %6.1f\n",fahr, celsius);
why all these redundant casts such as
1)(const char *)"%3.0f %6.1f\n"
2)(int)((int (*)(const char *, ...))