From: Matthias Apitz <guru@unixarea.de>
To: gcc-help@gcc.gnu.org
Subject: gcc on 64 bit && different behaviour while 'cast to pointer from integer of different size'
Date: Wed, 22 Jul 2015 07:46:00 -0000 [thread overview]
Message-ID: <20150722074604.GA3238@c720-r276659> (raw)
Hello,
We compile on Solaris SPARC a big software project and for the first
time to support 64 bit. The historical grown C code was never written
with 64 bit in mind and on 32 bit pointers and integers are of the same size.
We have two different version of gcc available on this host, 3.4.3 and 4.4.2.
I have below a small example where a function fun() should return a char pointer
and due to its missing declaration as 'extern char *fun();' the compiler
treats the function as integer returning and produce the warning
cast to pointer from integer of different size
Until now total clear. The questions are:
Why does the gcc 3.4.3 correct this problem on the fly and stores
the full 64 bit pointer into the receiving char pointer, while the
gcc 4.4.2 does not?
When this feature or behaviour was changed after gcc 3.4.3?
Is this somehow a command line flag for gcc to control the behaviour?
For sure, the correct way is to change the (hundreds) of places where
the function declaration is missing.
Thanks
matthias
$ uname -a
SunOS srap01dxle 5.10 Generic_150400-17 sun4u sparc SUNW,SPARC-Enterprise
$ /usr/local/bin/gcc --version
gcc (GCC) 4.4.2
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ /usr/sfw/bin/gcc --version
gcc (GCC) 3.4.3 (csl-sol210-3_4-branch+sol_rpath)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ cat main.c
/* main.c */
#include <stdio.h>
/* extern char* fun(); */
main(int argc, char **argv)
{
char *p = (char *) NULL;
p = (char *) fun();
printf("main has p as: %016lx\n", p);
printf("main has p as: %s\n", p);
}
$ cat fun.c
/* fun.c */
#include <stdio.h>
char *fun()
{
char *p = "fun";
printf("fun() returns pointer p as: %016lx\n", p);
return (p);
}
$ /usr/sfw/bin/gcc -m64 main.c fun.c ; ./a.out
main.c: In function `main':
main.c:9: warning: cast to pointer from integer of different size
fun() returns pointer p as: 0000000100000c80
main has p as: 0000000100000c80
main has p as: fun
$ /usr/local/bin/gcc -m64 main.c fun.c ; ./a.out
main.c: In function 'main':
main.c:9: warning: cast to pointer from integer of different size
fun() returns pointer p as: 0000000100000c30
main has p as: 0000000000000c30
Segmentation Fault (core dumped)
--
Matthias Apitz, guru@unixarea.de, http://www.unixarea.de/ +49-176-38902045
No! Nein! ¡No! ÎÏι! -- ÎÏ
ÏαÏιÏÏοÏμε!
next reply other threads:[~2015-07-22 7:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-22 7:46 Matthias Apitz [this message]
2015-07-22 7:59 ` Andrew Haley
[not found] ` <20150722080706.GB3238@c720-r276659>
2015-07-22 8:11 ` Andrew Haley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150722074604.GA3238@c720-r276659 \
--to=guru@unixarea.de \
--cc=gcc-help@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).