473,320 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Why is C compiler stubborn ?

Or may be I am stubborn or dumb ... of not putting in a * in the
typecast.
This is code I am worrying about

long long b=1;
int *address ;
address=(int)&b;
printf ("%x %x \n",*(address+1)*address);

when I compile the code I get this warning from gcc (although it
allows me to execute and gives me the desired result).

warning: assignment makes pointer from integer without a cast

I get errors for the same in some other compilers.

and when I put address=(int *)&b; I get a clean output.

Why should it give this warning ? It can consider &b as an integer and
proceed..

Any thoughts ?

regards
Jean

Mar 13 '07 #1
45 2219

On Tue, 12 Mar 2007 al*******@rediffmail.com wrote:
>
Or may be I am stubborn or dumb ... of not putting in a * in the
typecast.
This is code I am worrying about

long long b=1;
int *address ;
address=(int)&b;
printf ("%x %x \n",*(address+1)*address);
You're doing too many things wrong at once. Since you defined
'address' to be of type (int*), it's a pointer. Therefore, you can't
assign an 'int' to it; that's what GCC is warning you about.

But you also can't (portably nor correctly) convert a value of
type (long long *) to 'int', which is what you're doing on the
right-hand side of that assignment.

And then inside the second argument to 'printf', you're trying
to multiply 'address' by *(address+1), which you also can't do.
I think that in that case you simply left out a comma, though.
(Which means you type carelessly, and therefore what you type /here/
may bear no relationship to what you type in your actual program.
Which is why some people may choose not to waste time on it.)

Finally, assuming the presence of the missing comma, you're trying
to treat two values of type 'int' as if they were 'unsigned int',
which is not a good idea.

You should try compiling with 'gcc -O2 -W -Wall -ansi -pedantic',
and fix the mistakes that GCC points out. Don't just ignore them, or
try to cover them up with casts; you won't learn anything that way,
and your code will still be wrong.

HTH,
-Arthur
Mar 13 '07 #2
al*******@rediffmail.com wrote, On 13/03/07 06:47:
Or may be I am stubborn or dumb ... of not putting in a * in the
typecast.
Firstly there is no such thing as a typecast. Stop using whatever book
or online resource tells you there is because the author obviously does
not know the language.
This is code I am worrying about

long long b=1;
int *address ;
address=(int)&b;
Address is a pointer to int, b is a long long, what on earth makes you
think that forcing address to point to b could possibly be a sensible
thing to do?
printf ("%x %x \n",*(address+1)*address);
%x is the wrong format specifier for a pointer. You need to use %p and
also cast the pointer to a void* as that is what %p expects.
Dereferencing a pointer to beyond the end of an object is not allowed,
anything can happen (if you expected it to pick up the value of address
then be aware that I regularly use a machine there this will *not* happen.

Also, this if obviously *not* the code that you compiled since it is
missing a comma. *Always* copy and paste the code, *never* retype it.
Also, always provide a *compile* program, not a small fragment.
>
when I compile the code I get this warning from gcc (although it
allows me to execute and gives me the desired result).
I've managed to walk around on a busy motorway in the middle of the day,
should I ignore the warnings telling me not to do it just because
nothing happened to me when I did it before?
warning: assignment makes pointer from integer without a cast

I get errors for the same in some other compilers.

and when I put address=(int *)&b; I get a clean output.

Why should it give this warning ? It can consider &b as an integer and
proceed..

Any thoughts ?
First rule of casting, don't do it. If you corrected all the problems so
that you were doing something legal the cast would not be required.

Casting to int obviously creates an int, what makes you think that an
int is the same as a pointer to an int? Do you think the sign post
pointing to the centre of town is actually the centre of town?

I suggest you start reading a good C text book from page 1. I suggest
The C Programming Language 2nd Edition by Kernighan & Ritchie, and also
when you have problems the comp.lang.c FAQ at http://c-faq.com/
--
Flash Gordon
Mar 13 '07 #3
alertj...@rediffmail.com wrote:
Or may be I am stubborn or dumb ... of not putting in a * in the
typecast.
The correct term is cast, not typecast.
This is code I am worrying about

long long b=1;
int *address ;
address=(int)&b;
printf ("%x %x \n",*(address+1)*address);
Why do want to the that? The correct way would be:

long long b = 1;
long long *address;
address = &b;
printf("%x %x\n", *address+1, *address);
when I compile the code I get this warning from gcc (although it
allows me to execute and gives me the desired result).

warning: assignment makes pointer from integer without a cast
Not only that, you're using the wrong pointer type. You need a pointer
to type long long to point to an object of type long long and
similarly for others. The pointer type void can point to any object,
but it can only be used after an appropriate cast.
I get errors for the same in some other compilers.
Because it invokes undefined behaviour. Your printf statement is also
wrong, as it stands, though I think it's typo on your part. In future,
cut and paste code, don't retype.
and when I put address=(int *)&b; I get a clean output.
It's still leading to undefined behaviour, because you're casting the
pointer value yielded by &b from one type to another. Except for
conversion to and from void and char pointer types, other conversions
invoke implementation defined behaviour. It may work under one
implementation, but may fail under another.
Why should it give this warning ? It can consider &b as an integer and
proceed..
It a value of type pointer to long long.

Mar 13 '07 #4
On Mar 13, 2:47 am, alertj...@rediffmail.com wrote:
Or may be I am stubborn or dumb ... of not putting in a * in the
typecast.
This is code I am worrying about

long long b=1;
int *address ;
address=(int)&b;
printf ("%x %x \n",*(address+1)*address);

when I compile the code I get this warning from gcc (although it
allows me to execute and gives me the desired result).

warning: assignment makes pointer from integer without a cast

I get errors for the same in some other compilers.

and when I put address=(int *)&b; I get a clean output.

Why should it give this warning ? It can consider &b as an integer and
proceed..
No, it can't.

Given
long long b=1;
int *address ;
then
&b is a pointer to a long long, /not/ a pointer to an integer
there's no guarantee that two different pointer types have the same
length, format, or content constraints.

/Then/ you go further and make this
(int)&b
There is no guarantee that a pointer of any type can be mapped into
integer space

And finally, you take the worst step and
address = (int)&b;
which then tries to map an integer (which has already been mapped from
a pointer to long long) back as a pointer to int.

Your compiler is correct in warning you that you are incorrectly
making a pointer from an integer. Too many problems (including
alignment and value range mismappings) can occur when you do this, and
the compiler knows that if you've coded it this way, then you probably
don't realize what the dangers are.

HTH
--
Lew

Mar 13 '07 #5
On 13 Mar, 06:47, alertj...@rediffmail.com wrote:
Or may be I am stubborn or dumb ... of not putting in a * in the
typecast.
This is code I am worrying about

long long b=1;
int *address ;
address=(int)&b;
printf ("%x %x \n",*(address+1)*address);

when I compile the code I get this warning from gcc (although it
allows me to execute and gives me the desired result).

warning: assignment makes pointer from integer without a cast
You are taking the address of a "long long", cast to an "int", which
you are storing in a "pointer to int".

What could conceivably persuade you that this is correct (let alone
portable) code? Stop whinging about the compiler warnings, and write
some sensible code.

Mar 13 '07 #6
alertj...@rediffmail.com wrote:
Or may be I am stubborn or dumb ... of not putting in a * in the
typecast.
This is code I am worrying about

long long b=1;
int *address ;
address=(int)&b;
eek! why are you trying to shove an int into a pointer?
ITYM
address = (int*)&b;
printf ("%x %x \n",*(address+1)*address);
eek! you told printf you were going to give it two ints and then gave
it <pause>
um, well you only gave it one argument.

*(address + 1) * address
*(<int*+ 1) * <int*>
*(<invalid int*>) * <int*>
((address + 1) does not evaluate to a valid pointer)
<undefined int* <int*>

so you dereferenced an invalid pointer to yield an int (sort of),
then multiplied an int by an int*. What effect were you expecting?
My DS9000 tried to add the sun and earth together.

when I compile the code I get this warning from gcc (although it
allows me to execute and gives me the desired result).
amazing

warning: assignment makes pointer from integer without a cast

I get errors for the same in some other compilers.
I think they're trying to tell you something...

and when I put address=(int *)&b; I get a clean output.
yes

Why should it give this warning ? It can consider &b as an integer and
proceed..
because (int)&b casts a long long into an <int>
and address is an <int*>. Not an int but a ptr-to-int

they do not have the same type.
--
Nick Keighley

My god it's full of stars!
Dave Bowman, on seeing HAL's source code

Mar 13 '07 #7
On Mar 13, 10:35 am, "Nick Keighley"
<nick_keighley_nos...@hotmail.comwrote:
alertj...@rediffmail.com wrote:
Or may be I am stubborn or dumb ... of not putting in a * in the
typecast.
[snip]
Why should it give this warning ? It can consider &b as an integer and
proceed..

because (int)&b casts a long long into an <int>
ITYM "because (int)&b casts the address of a long long into an <int>"
and address is an <int*>. Not an int but a ptr-to-int

they do not have the same type.
--
Lew
Mar 13 '07 #8
santosh wrote:
alertj...@rediffmail.com wrote:
Or may be I am stubborn or dumb ... of not putting in a * in the
typecast.

The correct term is cast, not typecast.
This is code I am worrying about

long long b=1;
int *address ;
address=(int)&b;
printf ("%x %x \n",*(address+1)*address);

Why do want to the that? The correct way would be:

long long b = 1;
long long *address;
address = &b;
printf("%x %x\n", *address+1, *address);
Sorry about this. The %x format specifier is for unsigned int. For
printing long long values use:

printf("%lld\n", *address);

I left out *(address+1) because in C though you can point a pointer to
one element past an array, (a single object is considered as an array
of one element), you cannot deference it to take the value. Doing so
invokes undefined behaviour.

<snip>

Mar 13 '07 #9
On Mar 13, 8:21 pm, Flash Gordon <s...@flash-gordon.me.ukwrote:
alertj...@rediffmail.com wrote, On 13/03/07 06:47:
Or may be I am stubborn or dumb ... of not putting in a * in the
typecast.

Firstly there is no such thing as a typecast. Stop using whatever book
or online resource tells you there is because the author obviously does
not know the language.
It is not uncommon to use "typecast" to mean "cast". It can even
help to disambiguate from some of the other meanings of "cast".

Mar 13 '07 #10
In article <r0************@news.flash-gordon.me.uk>,
Flash Gordon <sp**@flash-gordon.me.ukwrote:
>Firstly there is no such thing as a typecast.
I can see an argument - even if I don't always agree with it - for not
using everyday or standard computer science terms here when they
conflict with their use in the C standard, but rejecting the use of a
common computer science term merely because the C standard doesn't
happen to use it seems quite excessive.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Mar 13 '07 #11
Old Wolf said:
On Mar 13, 8:21 pm, Flash Gordon <s...@flash-gordon.me.ukwrote:
>alertj...@rediffmail.com wrote, On 13/03/07 06:47:
Or may be I am stubborn or dumb ... of not putting in a * in the
typecast.

Firstly there is no such thing as a typecast. Stop using whatever
book or online resource tells you there is because the author
obviously does not know the language.

It is not uncommon to use "typecast" to mean "cast".
Right - it is not uncommon for people to misuse words. That doesn't mean
we should encourage the practice.
It can even
help to disambiguate from some of the other meanings of "cast".
C has only one technical meaning for "cast", so the question doesn't
arise.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Mar 13 '07 #12
Richard Tobin wrote, On 13/03/07 22:18:
In article <r0************@news.flash-gordon.me.uk>,
Flash Gordon <sp**@flash-gordon.me.ukwrote:
>Firstly there is no such thing as a typecast.

I can see an argument - even if I don't always agree with it - for not
using everyday or standard computer science terms here when they
conflict with their use in the C standard, but rejecting the use of a
common computer science term merely because the C standard doesn't
happen to use it seems quite excessive.
I consider it important to use the correct terminology for C when
discussing C so that people can then look things up easily in a decent C
text book such as K&R2.
--
Flash Gordon
Mar 14 '07 #13
Richard Tobin wrote:
In article <r0************@news.flash-gordon.me.uk>,
Flash Gordon <sp**@flash-gordon.me.ukwrote:
>>Firstly there is no such thing as a typecast.

I can see an argument - even if I don't always agree with it - for not
using everyday or standard computer science terms here when they
conflict with their use in the C standard, but rejecting the use of a
common computer science term merely because the C standard doesn't
happen to use it seems quite excessive.
The only place I've come across the term `typecast` is in
postings to CLC from people who don't realise that the C
term is `cast`.

Perhaps I should get out more?

--
Chris "electric hedgehog" Dollin
"There's a doorway / where there was a wall" - The Fyreworks,
/Master Humpries Clock/

Mar 14 '07 #14
Chris Dollin wrote:
Richard Tobin wrote:
In article <r0************@news.flash-gordon.me.uk>,
Flash Gordon <sp**@flash-gordon.me.ukwrote:
>Firstly there is no such thing as a typecast.
I can see an argument - even if I don't always agree with it - for not
using everyday or standard computer science terms here when they
conflict with their use in the C standard, but rejecting the use of a
common computer science term merely because the C standard doesn't
happen to use it seems quite excessive.

The only place I've come across the term `typecast` is in
postings to CLC from people who don't realise that the C
term is `cast`.
I've come across that term in various books and tutorials on
programming languages. Usually it's a book on C, but I'm sure I've
encountered it in material for other languages too, though I can't
remember right now.

It's understandable, though not desirable, that most programming
language books and tutorials are not as precise and rigorous as their
official definition.

Mar 14 '07 #15
Chris Dollin wrote:
>
.... snip ...
>
The only place I've come across the term `typecast` is in
postings to CLC from people who don't realise that the C
term is `cast`.

Perhaps I should get out more?
I think it has to do with Linotype machines and molten lead. :-)

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Mar 14 '07 #16
santosh wrote, On 14/03/07 09:13:
Chris Dollin wrote:
>Richard Tobin wrote:
>>In article <r0************@news.flash-gordon.me.uk>,
Flash Gordon <sp**@flash-gordon.me.ukwrote:

Firstly there is no such thing as a typecast.
I can see an argument - even if I don't always agree with it - for not
using everyday or standard computer science terms here when they
conflict with their use in the C standard, but rejecting the use of a
common computer science term merely because the C standard doesn't
happen to use it seems quite excessive.
The only place I've come across the term `typecast` is in
postings to CLC from people who don't realise that the C
term is `cast`.

I've come across that term in various books and tutorials on
programming languages. Usually it's a book on C, but I'm sure I've
encountered it in material for other languages too, though I can't
remember right now.

It's understandable, though not desirable, that most programming
language books and tutorials are not as precise and rigorous as their
official definition.
I've yet to see a good reason why one should use the term typecast
instead of cast. A beginner at programming won't know either term so
learning the correct terminology for C is no hardship in this case, and
someone more experienced who has come across the term typecast is highly
unlikely to be confused by C books using the term cast.

So far I have only seen the term typecast used by people who do not know
the language and in resources which are bad for other reasons. So I
think the only reason some beginners use it is that they are learning
from poor resources, and the use of the word typecast is a good
indicator that the person using it has a poor knowledge of C even if the
person using it is the author of a book on C.
--
Flash Gordon
Mar 14 '07 #17
in 724333 20070314 132750 Flash Gordon <sp**@flash-gordon.me.ukwrote:
>santosh wrote, On 14/03/07 09:13:
>Chris Dollin wrote:
>>Richard Tobin wrote:

In article <r0************@news.flash-gordon.me.uk>,
Flash Gordon <sp**@flash-gordon.me.ukwrote:

Firstly there is no such thing as a typecast.
I can see an argument - even if I don't always agree with it - for not
using everyday or standard computer science terms here when they
conflict with their use in the C standard, but rejecting the use of a
common computer science term merely because the C standard doesn't
happen to use it seems quite excessive.
The only place I've come across the term `typecast` is in
postings to CLC from people who don't realise that the C
term is `cast`.

I've come across that term in various books and tutorials on
programming languages. Usually it's a book on C, but I'm sure I've
encountered it in material for other languages too, though I can't
remember right now.

It's understandable, though not desirable, that most programming
language books and tutorials are not as precise and rigorous as their
official definition.

I've yet to see a good reason why one should use the term typecast
instead of cast. A beginner at programming won't know either term so
learning the correct terminology for C is no hardship in this case, and
someone more experienced who has come across the term typecast is highly
unlikely to be confused by C books using the term cast.

So far I have only seen the term typecast used by people who do not know
the language and in resources which are bad for other reasons. So I
think the only reason some beginners use it is that they are learning
from poor resources, and the use of the word typecast is a good
indicator that the person using it has a poor knowledge of C even if the
person using it is the author of a book on C.
--
Flash Gordon

It seems that none of you have ever read a Pascal or Delphi manual !!
Mar 14 '07 #18
Bob Martin wrote:
It seems that none of you have ever read a Pascal or Delphi manual !!
I've read several Pascal manuals, but that was in the days when
Pascal didn't have a "typecast" (whatever that is).

--
Chris "electric hedgehog" Dollin
"How am I to understand if you won't teach me?" - Trippa, /Falling/

Mar 14 '07 #19
In article <r0************@news.flash-gordon.me.uk>,
Flash Gordon <sp**@flash-gordon.me.ukwrote:
>al*******@rediffmail.com wrote, On 13/03/07 06:47:
> printf ("%x %x \n",*(address+1)*address);

%x is the wrong format specifier for a pointer. You need to use %p and
also cast the pointer to a void* as that is what %p expects.
Nitpick: It's not strictly necessary to cast the pointer. You do need
to make sure that it fgets converted to a void* through some mechanism,
but if you already have an object of the correct type (void *) floating
around with the suitably converted pointer value you want to print,
you can just give printf the value of that object without casting it:
--------
/*A bit verbose if you're not using vp anywhere else, but perfectly valid*/
void *vp=my_pointer_value;
printf("%p\n",vp);

/*leaks memory but otherwise correct*/
printf("%p\n",malloc(42));

/*Not quite incorrect, but gratuitiously wrong in several ways*/
printf("%p\n",(void *)(int *)malloc(sizeof(int)));
--------

Giving non-void pointers to printf is, however, one of the few situations
where pointer casts are all of correct, useful, and CLC-conforming.
dave

--
Dave Vandervies dj******@csclub.uwaterloo.ca
Since I have seen that proof, I always have a good laugh when someone
claims that everything can be written without goto.
--Christian Bau in comp.lang.c
Mar 14 '07 #20
On 2007-03-14, Bob Martin <bo********@excite.comwrote:

<snipped contention over typecast>
>
It seems that none of you have ever read a Pascal or Delphi manual !!
Seeing as how we discuss only the C language here, I wonder
how you could consider that statement to be relevant at all.

--
Lelanthran Manickum
|Americans' greatest fear is that America will turn out to
|have been a phenomenon, not a civilization.
| -- Shirley Hazzard, "Transit of Venus"
Mar 15 '07 #21
in 724501 20070315 080211 goose <go***@webmail.co.zawrote:
>On 2007-03-14, Bob Martin <bo********@excite.comwrote:

<snipped contention over typecast>
>>
It seems that none of you have ever read a Pascal or Delphi manual !!

Seeing as how we discuss only the C language here, I wonder
how you could consider that statement to be relevant at all.
Please read the thread before replying. At least two people said they had
never heard of the term "typecast" being used in ANY programming language.
Mar 15 '07 #22
Flash Gordon wrote:
....
I've yet to see a good reason why one should use the term typecast
instead of cast. A beginner at programming won't know either term so
learning the correct terminology for C is no hardship in this case, and
someone more experienced who has come across the term typecast is highly
unlikely to be confused by C books using the term cast.

So far I have only seen the term typecast used by people who do not know
the language and in resources which are bad for other reasons. So I
think the only reason some beginners use it is that they are learning
from poor resources, and the use of the word typecast is a good
indicator that the person using it has a poor knowledge of C even if the
person using it is the author of a book on C.
Take a look at this:
http://www.cs.cf.ac.uk/Dave/C/node9....00000000000000

Is it a bad one? It's listed at http://www.iso-9899.info/wiki/Main_Page.

Yevgen
Mar 15 '07 #23
Bob Martin said:
in 724501 20070315 080211 goose <go***@webmail.co.zawrote:
>>On 2007-03-14, Bob Martin <bo********@excite.comwrote:

<snipped contention over typecast>
>>>
It seems that none of you have ever read a Pascal or Delphi manual
!!

Seeing as how we discuss only the C language here, I wonder
how you could consider that statement to be relevant at all.

Please read the thread before replying. At least two people said they
had never heard of the term "typecast" being used in ANY programming
language.
I hadn't, either - except (erroneously) in C and, later, C++.

So I hauled five language texts at random from my shelf, non-critically
(I didn't validate for whether I liked the described languages, or
indeed the authors!) and glanced through their indices:

"Programming with PASCAL" (Konvalina & Wileman, 1987). I found no entry
for "typecast".

"The Java Programming Language" (Arnold, Gosling, and Holmes, 2000). The
entry "type casting" does appear, but I could not find the word
"typecast" itself. "Type casting" is, of course, to "typecast" as
"operator overloading" is to "operatoroverload".

"Perl in a Nutshell" (Siever, Spainbour & Patwardban. 1999). I found no
index entry for "typecast".

"The C++ Programming Language" (Stroustrup, 2000). I found no index
entry for "typecast".

"PHP and MySQL" (Ullman, 2005). An entry exists for "type casting" (see
above), but nothing under "typecast" or "typecasting".

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Mar 15 '07 #24
Yevgen Muntyan <mu****************@tamu.eduwrote:
Flash Gordon wrote:
...
So far I have only seen the term typecast used by people who do not know
the language and in resources which are bad for other reasons. So I
think the only reason some beginners use it is that they are learning
from poor resources, and the use of the word typecast is a good
indicator that the person using it has a poor knowledge of C even if the
person using it is the author of a book on C.

Take a look at this:
http://www.cs.cf.ac.uk/Dave/C/node9....00000000000000

Is it a bad one?
When it says: "A good rule to follow is: If in doubt cast."!? That's not
bad, that's irretrievably rotten.

Richard
Mar 15 '07 #25
Richard Bos wrote, On 15/03/07 10:25:
Yevgen Muntyan <mu****************@tamu.eduwrote:
>Flash Gordon wrote:
...
>>So far I have only seen the term typecast used by people who do not know
the language and in resources which are bad for other reasons. So I
think the only reason some beginners use it is that they are learning
from poor resources, and the use of the word typecast is a good
indicator that the person using it has a poor knowledge of C even if the
person using it is the author of a book on C.
Take a look at this:
http://www.cs.cf.ac.uk/Dave/C/node9....00000000000000

Is it a bad one?

When it says: "A good rule to follow is: If in doubt cast."!? That's not
bad, that's irretrievably rotten.
So my usage of typecast as an indicator of poor knowledge stands
unchanged. I did look at the page and I agree with Richard Bos. I would
have done something about that link on the Wiki (probably added a note
on the talk page) but they made it too difficult.
--
Flash Gordon
Mar 15 '07 #26
in 724514 20070315 094232 Richard Heathfield <rj*@see.sig.invalidwrote:
>Bob Martin said:
>in 724501 20070315 080211 goose <go***@webmail.co.zawrote:
>>>On 2007-03-14, Bob Martin <bo********@excite.comwrote:

<snipped contention over typecast>
It seems that none of you have ever read a Pascal or Delphi manual
!!

Seeing as how we discuss only the C language here, I wonder
how you could consider that statement to be relevant at all.

Please read the thread before replying. At least two people said they
had never heard of the term "typecast" being used in ANY programming
language.

I hadn't, either - except (erroneously) in C and, later, C++.

So I hauled five language texts at random from my shelf, non-critically
(I didn't validate for whether I liked the described languages, or
indeed the authors!) and glanced through their indices:

"Programming with PASCAL" (Konvalina & Wileman, 1987). I found no entry
for "typecast".

"The Java Programming Language" (Arnold, Gosling, and Holmes, 2000). The
entry "type casting" does appear, but I could not find the word
"typecast" itself. "Type casting" is, of course, to "typecast" as
"operator overloading" is to "operatoroverload".

"Perl in a Nutshell" (Siever, Spainbour & Patwardban. 1999). I found no
index entry for "typecast".

"The C++ Programming Language" (Stroustrup, 2000). I found no index
entry for "typecast".

"PHP and MySQL" (Ullman, 2005). An entry exists for "type casting" (see
above), but nothing under "typecast" or "typecasting".
Google for typecast shows 961,000 hits, including most Borland sites on
Delphi and Object Pascal.

It has been around for at least 25 years and I find it hard to believe that there
are serious programmers who have never come across it.

Mar 15 '07 #27
Bob Martin wrote:
typecast
http://dictionary.reference.com/search?q=typecast

--
pete
Mar 16 '07 #28
Bob Martin wrote:
typecast
N869
6.5.4 Cast operators
[#4] Preceding an expression by a parenthesized type name
converts the value of the expression to the named type.
This construction is called a cast.

6.3.2.3 Pointers
[#3] An integer constant expression with the value 0, or
such an expression cast to type void *, is called a null
pointer constant.

--
pete
Mar 16 '07 #29
Bob Martin wrote, On 15/03/07 19:03:
in 724514 20070315 094232 Richard Heathfield <rj*@see.sig.invalidwrote:
>Bob Martin said:
>>in 724501 20070315 080211 goose <go***@webmail.co.zawrote:
On 2007-03-14, Bob Martin <bo********@excite.comwrote:

<snipped contention over typecast>
<snip mode discussion about typecast and its use in general computing>
>So I hauled five language texts at random from my shelf, non-critically
(I didn't validate for whether I liked the described languages, or
indeed the authors!) and glanced through their indices:
<snip>
>"PHP and MySQL" (Ullman, 2005). An entry exists for "type casting" (see
above), but nothing under "typecast" or "typecasting".

Google for typecast shows 961,000 hits, including most Borland sites on
Delphi and Object Pascal.

It has been around for at least 25 years and I find it hard to believe that there
are serious programmers who have never come across it.
The work is obviously a far larger place than you had believed. Probably
for the 1st 10 years of my professional career I had never needed to do
any forced conversion between types apart from the odd use of 'ord' and
the 'chr' in Pascal (if I've remembered the function names correctly).
Since I always considered the ability to mix floating point and integer
types to be natural I never even thought about whether there was some
specific general term for such conversions. Then I first came across the
need to force type conversions it was in C and K&R use the term cast, so
that is the term I use. So whilst it is *possible* I had heard the term
typecast and forgotten it, it is definitely true that it was not in
anything like regular use anywhere I've worked in the past 20 years.
--
Flash Gordon
Mar 16 '07 #30
in 724622 20070316 000018 Flash Gordon <sp**@flash-gordon.me.ukwrote:
>Bob Martin wrote, On 15/03/07 19:03:
>The work is obviously a far larger place than you had believed. Probably
for the 1st 10 years of my professional career I had never needed to do
any forced conversion between types apart from the odd use of 'ord' and
the 'chr' in Pascal (if I've remembered the function names correctly).
Since I always considered the ability to mix floating point and integer
types to be natural I never even thought about whether there was some
specific general term for such conversions. Then I first came across the
need to force type conversions it was in C and K&R use the term cast, so
that is the term I use. So whilst it is *possible* I had heard the term
typecast and forgotten it, it is definitely true that it was not in
anything like regular use anywhere I've worked in the past 20 years.
You obviously didn't write serious Pascal code ;-)
Mar 16 '07 #31
Bob Martin wrote:
in 724622 20070316 000018 Flash Gordon <sp**@flash-gordon.me.ukwrote:
>>Bob Martin wrote, On 15/03/07 19:03:
>>The work is obviously a far larger place than you had believed. Probably
for the 1st 10 years of my professional career I had never needed to do
any forced conversion between types apart from the odd use of 'ord' and
the 'chr' in Pascal (if I've remembered the function names correctly).
Since I always considered the ability to mix floating point and integer
types to be natural I never even thought about whether there was some
specific general term for such conversions. Then I first came across the
need to force type conversions it was in C and K&R use the term cast, so
that is the term I use. So whilst it is *possible* I had heard the term
typecast and forgotten it, it is definitely true that it was not in
anything like regular use anywhere I've worked in the past 20 years.

You obviously didn't write serious Pascal code ;-)
Do linkers [1] and functional-language interpreters [2]
count as serious?

[1] Actually a linking assembler, linking the assembler output
from the back-end of a compiler compiling a Pascalesque
language into loadable code.

My current recollection of the code is that there were
parts that were truly horrible ...

[2] Front-end compiled to combinator code a la Turner; back
end executed it; later versions used supercominators a la
Hughes.

--
Chris "electric hedgehog" Dollin
"No-one here is exactly what he appears." G'kar, /Babylon 5/

Mar 16 '07 #32
Chris Dollin wrote, On 16/03/07 10:25:
Bob Martin wrote:
>in 724622 20070316 000018 Flash Gordon <sp**@flash-gordon.me.ukwrote:
>>Bob Martin wrote, On 15/03/07 19:03:
The work is obviously a far larger place than you had believed. Probably
for the 1st 10 years of my professional career I had never needed to do
any forced conversion between types apart from the odd use of 'ord' and
the 'chr' in Pascal (if I've remembered the function names correctly).
Since I always considered the ability to mix floating point and integer
types to be natural I never even thought about whether there was some
specific general term for such conversions. Then I first came across the
need to force type conversions it was in C and K&R use the term cast, so
that is the term I use. So whilst it is *possible* I had heard the term
typecast and forgotten it, it is definitely true that it was not in
anything like regular use anywhere I've worked in the past 20 years.
You obviously didn't write serious Pascal code ;-)

Do linkers [1] and functional-language interpreters [2]
count as serious?
<snip>

Or circa 50000 lines of test rig software controlling lots of external
hardware for testing yet more external hardware. Or some nice big
embedded systems. Just to name a few :-)
--
Flash Gordon
Mar 16 '07 #33
>>>>"p" == pete <pf*****@mindspring.comwrites:

pBob Martin wrote:
>typecast
phttp://dictionary.reference.com/search?q=typecast

Dictionaries exist to record common usage, even when incorrect. Good
dictionaries indicate when a usage is considered archaic or incorrect;
bad ones don't. Only the most comprehensive dictionaries will include
definitions of technical jargon, and the theatrical and typographic
definitions of "typecast" are likely to be far more common anyway.
Finally, absence of evidence is not evidence of absence: the lack of a
technical definition for "typecast" in the dictionary does not mean
that the word does not have that meaning.

That said, it's been pretty conclusively established in this thread
that the correct term in C is "cast," while Delphi and Object Pascal
use "typecast." Given that we're discussing C, then, "cast" is the
correct form, but "typecast" is unambiguous. Is there any reason to
beat the horse further?

Charlton

--
Charlton Wilbur
cw*****@chromatico.net
Mar 16 '07 #34
Bob Martin <bo********@excite.comwrites:
in 724622 20070316 000018 Flash Gordon <sp**@flash-gordon.me.ukwrote:
>>Bob Martin wrote, On 15/03/07 19:03:
The work is obviously a far larger place than you had believed. Probably
for the 1st 10 years of my professional career I had never needed to do
any forced conversion between types apart from the odd use of 'ord' and
the 'chr' in Pascal (if I've remembered the function names correctly).
Since I always considered the ability to mix floating point and integer
types to be natural I never even thought about whether there was some
specific general term for such conversions. Then I first came across the
need to force type conversions it was in C and K&R use the term cast, so
that is the term I use. So whilst it is *possible* I had heard the term
typecast and forgotten it, it is definitely true that it was not in
anything like regular use anywhere I've worked in the past 20 years.

You obviously didn't write serious Pascal code ;-)
I've certainly written serious Pascal code, and I've never seen or
heard the word "typecast" applied in a Pascal context.

(I've never used Delphi and Object Pascal, though.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Mar 16 '07 #35
Keith Thompson <ks***@mib.orgwrites:
I've certainly written serious Pascal code, and I've never seen or
heard the word "typecast" applied in a Pascal context.

(I've never used Delphi and Object Pascal, though.)
It's a Turbo Pascal invention that came about around the release
of Turbo Pascal 4.0, c. 1987. (It might have been the 5.0
release, I'm not sure.)
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Mar 16 '07 #36
in 724816 20070316 203232 Keith Thompson <ks***@mib.orgwrote:
>Bob Martin <bo********@excite.comwrites:
>in 724622 20070316 000018 Flash Gordon <sp**@flash-gordon.me.ukwrote:
>>>Bob Martin wrote, On 15/03/07 19:03:
The work is obviously a far larger place than you had believed. Probably
for the 1st 10 years of my professional career I had never needed to do
any forced conversion between types apart from the odd use of 'ord' and
the 'chr' in Pascal (if I've remembered the function names correctly).
Since I always considered the ability to mix floating point and integer
types to be natural I never even thought about whether there was some
specific general term for such conversions. Then I first came across the
need to force type conversions it was in C and K&R use the term cast, so
that is the term I use. So whilst it is *possible* I had heard the term
typecast and forgotten it, it is definitely true that it was not in
anything like regular use anywhere I've worked in the past 20 years.

You obviously didn't write serious Pascal code ;-)

I've certainly written serious Pascal code, and I've never seen or
heard the word "typecast" applied in a Pascal context.

(I've never used Delphi and Object Pascal, though.)
What's with all you people rushing forward to boast of your ignorance?
Your not having come across "typecast" proves nothing.
Mar 17 '07 #37
Bob Martin <bo********@excite.comwrites:
in 724816 20070316 203232 Keith Thompson <ks***@mib.orgwrote:
>>Bob Martin <bo********@excite.comwrites:
[...]
>>You obviously didn't write serious Pascal code ;-)

I've certainly written serious Pascal code, and I've never seen or
heard the word "typecast" applied in a Pascal context.

(I've never used Delphi and Object Pascal, though.)

What's with all you people rushing forward to boast of your ignorance?
Your not having come across "typecast" proves nothing.
We're not boasting of our ignorance. We're refuting your apparent
claim that anyone who as written "serious Pascal code" must therefore
be familiar with the term.

I've come across the term "typecast", just not in the context of
Pascal.

Not that any of this either matters or is topical, of course.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Mar 17 '07 #38
in 724933 20070317 092551 Keith Thompson <ks***@mib.orgwrote:
>Bob Martin <bo********@excite.comwrites:
>in 724816 20070316 203232 Keith Thompson <ks***@mib.orgwrote:
>>>Bob Martin <bo********@excite.comwrites:
[...]
>>>You obviously didn't write serious Pascal code ;-)

I've certainly written serious Pascal code, and I've never seen or
heard the word "typecast" applied in a Pascal context.

(I've never used Delphi and Object Pascal, though.)

What's with all you people rushing forward to boast of your ignorance?
Your not having come across "typecast" proves nothing.

We're not boasting of our ignorance. We're refuting your apparent
claim that anyone who as written "serious Pascal code" must therefore
be familiar with the term.
You are not refuting anything - though you might be trying.
Mar 17 '07 #39
Bob Martin wrote:
Keith Thompson <ks***@mib.orgwrote:
.... snip ...
>>
We're not boasting of our ignorance. We're refuting your apparent
claim that anyone who as written "serious Pascal code" must
therefore be familiar with the term.

You are not refuting anything - though you might be trying.
On a quick review of your posts, I find zero content. PLONK.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Mar 17 '07 #40
Charlton Wilbur wrote:
>
>>>"p" == pete <pf*****@mindspring.comwrites:

pBob Martin wrote:
>typecast

phttp://dictionary.reference.com/search?q=typecast
Only the most comprehensive dictionaries will include
definitions of technical jargon
I never have and never will use a standard English dictionary
to get the definition of a technical term in C programming.
I am vehemently opposed to doing that.

--
pete
Mar 18 '07 #41
>>>>"p" == pete <pf*****@mindspring.comwrites:

pCharlton Wilbur wrote:
> >>>>"p" == pete <pf*****@mindspring.comwrites:
pBob Martin wrote:
>typecast
phttp://dictionary.reference.com/search?q=typecast
>Only the most comprehensive dictionaries will include
definitions of technical jargon
pI never have and never will use a standard English dictionary
pto get the definition of a technical term in C programming. I
pam vehemently opposed to doing that.

.....which is exactly what you did in the post I responded to.

Your opposition does not seem to be as vehement as you claim it is, sir.

Charlton
--
Charlton Wilbur
cw*****@chromatico.net
Mar 18 '07 #42
Charlton Wilbur wrote:
>
>>>"p" == pete <pf*****@mindspring.comwrites:

pCharlton Wilbur wrote:
> >>>>"p" == pete <pf*****@mindspring.comwrites:
>>
pBob Martin wrote:
>typecast
>>
phttp://dictionary.reference.com/search?q=typecast
>Only the most comprehensive dictionaries will include
>definitions of technical jargon

pI never have and never will use a standard English dictionary
pto get the definition of a technical term in C programming. I
pam vehemently opposed to doing that.

....which is exactly what you did in the post I responded to.
No.
"Typecast" isn't a technical term in C programming.

--
pete
Mar 18 '07 #43
pete wrote:
Charlton Wilbur wrote:
>>>>"p" == pete <pf*****@mindspring.comwrites:
pCharlton Wilbur wrote:
> >>>>"p" == pete <pf*****@mindspring.comwrites:
>>
pBob Martin wrote:
>typecast
>>
phttp://dictionary.reference.com/search?q=typecast
>Only the most comprehensive dictionaries will include
>definitions of technical jargon
pI never have and never will use a standard English dictionary
pto get the definition of a technical term in C programming. I
pam vehemently opposed to doing that.

....which is exactly what you did in the post I responded to.

No.
"Typecast" isn't a technical term in C programming.
In a sense it is, if you consider that a large corpus of C programmers
use that term. It's just not described in the Standard.

Mar 18 '07 #44
santosh wrote:
>
pete wrote:
"Typecast" isn't a technical term in C programming.

In a sense it is, if you consider that a large corpus of C programmers
use that term.
In that same sense,
a C programmer should also cast the return value of malloc.

The errors that regularly get corrected on this newsgroup
are committed by a large corpus of C programmers.

--
pete
Mar 18 '07 #45
Bob Martin wrote:
What's with all you people rushing forward to boast of your ignorance?
Your not having come across "typecast" proves nothing.
You implied that not having come across the term "typecast" meant that
one hadn't done serious Pascal programming.

It now appears even the ignorant (or perhaps just the ancient) can write
serious Pascal programs without knowing the term "typecast". Yes?

--
Chris "electric hedgehog" Dollin
"You've spotted a flaw in my thinking, Trev." Big Al, /The Beiderbeck Connection/

Mar 19 '07 #46

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jeff Epler | last post by:
Hello. Recently, Generator Comprehensions were mentioned again on python-list. I have written an implementation for the compiler module. To try it out, however, you must be able to rebuild...
22
by: Canonical Latin | last post by:
#include<iostream> int main() { char buff; std::cin.getline(buff,3); std::cin.getline(buff,3); std::cout << buff << endl; } Run at command prompt and input 1234567 what do you get as output?
19
by: Canonical Latin | last post by:
"Leor Zolman" <leor@bdsoft.com> wrote > "Canonical Latin" <javaplus@hotmail.com> wrote: > > > ... > >But I'm still curious as to the rational of having type >...
0
by: rollasoc | last post by:
Hi, I seem to be getting a compiler error Internal Compiler Error (0xc0000005 at address 535DB439): likely culprit is 'BIND'. An internal error has occurred in the compiler. To work around...
4
by: Quentin Yuan | last post by:
I always consider that the constant character strings of which literal value are the same lay out at the same logic address, in another words, every constant character string have only one copy in...
3
by: Rene | last post by:
Hello to all! For a long time I have been "fighting" a problem compiling an OpenGL program which uses GLUT. First I have put a question in a Watcom group (I want to use this compiler) to which I...
244
by: Ajinkya | last post by:
Can anyone suggest me a good compiler for(c/cpp) for windows? I tried dev cpp but its debugging facility is very poor.
87
by: rufus | last post by:
Is there a C-compiler (and for that matter C++ compiler) for windows that can be run from the commmand line?
159
by: bernard | last post by:
howdy! please recommend a good c compiler. - should be small - should be fast - should come with a good ide - should be inexpensive i am using windows os.
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.