* warning: cast from pointer
@ 2000-12-06 5:00 Dr. Unk
2000-12-07 5:00 ` arnoud
0 siblings, 1 reply; 4+ messages in thread
From: Dr. Unk @ 2000-12-06 5:00 UTC (permalink / raw)
I would like know how to clean up a source, so that I do not get any
more "warning: cast from pointer to integer of different size" or
"incompatible pointer" warnings. I know that in most cases they are
just that, warnings. But sometimes, I believe them to be the cause if
many seg faults and floating point exceptions.
My C knowledge is basic-level (2 courses taken). My system is an
AlphaPC 164SX, Glibc-2.1.3, GCC-2.95.2, Linux-2.2.17.
Thanks in advance.
Sent via Deja.com http://www.deja.com/
Before you buy.
^ permalink raw reply [flat|nested] 4+ messages in thread
* warning: cast from pointer
@ 2000-12-06 5:00 Dr. Unk
2000-12-06 5:00 ` Dan Pop
0 siblings, 1 reply; 4+ messages in thread
From: Dr. Unk @ 2000-12-06 5:00 UTC (permalink / raw)
I would like know how to clean up a source, so that I do not get any
more "warning: cast from pointer to integer of different size" or
"incompatible pointer" warnings. I know that in most cases they are
just that, warnings. But sometimes, I believe them to be the cause if
many seg faults and floating point exceptions.
My C knowledge is basic-level (2 courses taken). My system is an
AlphaPC 164SX, Glibc-2.1.3, GCC-2.95.2, Linux-2.2.17.
Thanks in advance.
Sent via Deja.com http://www.deja.com/
Before you buy.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: warning: cast from pointer
2000-12-06 5:00 Dr. Unk
@ 2000-12-06 5:00 ` Dan Pop
0 siblings, 0 replies; 4+ messages in thread
From: Dan Pop @ 2000-12-06 5:00 UTC (permalink / raw)
In <90l6uf$v8h$1@nnrp1.deja.com> Dr. Unk <dr_unk@hotmail.com> writes:
>I would like know how to clean up a source, so that I do not get any
>more "warning: cast from pointer to integer of different size" or
>"incompatible pointer" warnings. I know that in most cases they are
>just that, warnings.
They *always* indicate bugs in your code. If your code "works", it is
purely by accident.
>But sometimes, I believe them to be the cause if
>many seg faults and floating point exceptions.
Indeed.
>My C knowledge is basic-level (2 courses taken). My system is an
>AlphaPC 164SX, Glibc-2.1.3, GCC-2.95.2, Linux-2.2.17.
Make sure that you include the required headers for *all* the library
functions you're calling and that you declare *all* your functions before
calling them.
Example of buggy code giving the diagnostic mentioned above on Alpha:
ues5:~/tmp 333> cat test.c
int main()
{
char *p = (char *)malloc(100); /* malloc *requires* <stdlib.h> */
return 0;
}
ues5:~/tmp 334> gcc test.c
test.c: In function `main':
test.c:3: warning: cast to pointer from integer of different size
ues5:~/tmp 335> gcc -Wall test.c
test.c: In function `main':
test.c:3: warning: implicit declaration of function `malloc'
test.c:3: warning: cast to pointer from integer of different size
test.c:3: warning: unused variable `p'
As you can see, -Wall also told you what is the exact problem triggering
the other warning. You *really* should get your code to compile cleanly
with gcc -Wall.
The right way to fix my example is to:
1. Include <stdlib.h>
2. Drop the cast in front of malloc. This cast will give a clean
compile (if you don't use -Wall) on a 32-bit platform, masking the
bug in the code.
Dan
--
Dan Pop
CERN, IT Division
Email: Dan.Pop@cern.ch
Mail: CERN - IT, Bat. 31 1-014, CH-1211 Geneve 23, Switzerland
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: warning: cast from pointer
2000-12-06 5:00 warning: cast from pointer Dr. Unk
@ 2000-12-07 5:00 ` arnoud
0 siblings, 0 replies; 4+ messages in thread
From: arnoud @ 2000-12-07 5:00 UTC (permalink / raw)
For those cases that the warning is "just a warning" you should (MUST) do
the
cast your self e.g. if you have:
char cPrevCounter;
int iPnt;
cPrevCounter = (char)iPnt;
instead of
cPrevCounter = iPnt;
In this way you (or other reviewing your code) knows that you DID think
over that
there is the possiblity of cast problem.
If the warning isn't jus a warning you should fix the code for this!!!
Regards,
Arnoud.
"Dr. Unk" wrote:
> I would like know how to clean up a source, so that I do not get any
> more "warning: cast from pointer to integer of different size" or
> "incompatible pointer" warnings. I know that in most cases they are
> just that, warnings. But sometimes, I believe them to be the cause if
> many seg faults and floating point exceptions.
>
> My C knowledge is basic-level (2 courses taken). My system is an
> AlphaPC 164SX, Glibc-2.1.3, GCC-2.95.2, Linux-2.2.17.
>
> Thanks in advance.
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2000-12-07 5:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2000-12-06 5:00 warning: cast from pointer Dr. Unk
2000-12-07 5:00 ` arnoud
-- strict thread matches above, loose matches on Subject: below --
2000-12-06 5:00 Dr. Unk
2000-12-06 5:00 ` Dan Pop
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox