Hello,
I have a test program that is compiled fine on a 32 bits redhat linux using gcc :
*************** ********
main (argc, argv)
int argc;
char *argv[];
{
int *ka;
int nka;
/* allocation dynamique entiere */
ka = (int *) malloc(nka * sizeof(int));
if (!ka) {
printf ("<ERROR> : Out of heap space (malloc) !\n");
printf ("<ERROR> : %d int words required\n", nka);
exit (-1);
}
}
*************** ********
But under linux suse AMD opteron 64, i get this message from the compiler :
warning: cast to pointer from integer of different size
Any explanation ?
Regards,
Lionel.
--
-=O=------------------------------------------=O=-
Lionel Valéro
Analyste Informatique Département Génie Chimique
École Polytechnique de Montréal
C.P. 6079, succ. centre-ville
Montréal (Québec) H3C 3A7
Tel: (514) 340 - 4711 # 4805 / C552
Fax: (514) 340 - 4159
-=O=------------------------------------------=O=-
Nov 13 '05
54 3594
glen herrmannsfeldt <ga*@ugcs.calte ch.edu> writes: E. Robert Tisdale wrote: Barry Schwarz wrote: On a machine where the method of returning a pointer differs from the method of returning an int (such as using a different register), Please tell us which machine does this.
Any machine where sizeof(int) is different than sizeof(char*) will do.
Though this is more OS or function calling convention dependent than machine dependent.
Note that this (calling malloc() with no prototype) may happen to work
on some systems even if sizeof(int) > sizeof(void*). For example, if
int is 32 bits, void* is 64 bits, the value returned by malloc happens
to have the 32 high-order bits all zero, the machine is little-endian
(I think), and a few other unstated assumptions hold, you could
accidentally extract a valid 64-bit pointer from what the compiler
thinks is a 32-bit int result.
This is, of course, deep in the realm of undefined behavior. "Happens
to work" is actually a bad thing, because it can make it more
difficult to detect bugs. (Hey, maybe we should start referring to
this kind of thing as "HTW". 8-)})
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
(Note new e-mail address)
[On mis-declaring malloc() and having code fail, in answer to
"where might this happen"] Barry Schwarz wrote: On a machine where the method of returning a pointer differs from the method of returning an int (such as using a different register),
E. Robert Tisdale wrote: Please tell us which machine does this.
In article <nh7zb.6213$_M. 26715@attbi_s54 >,
glen herrmannsfeldt <ga*@ugcs.calte ch.edu> wrote:Any machine where sizeof(int) is different than sizeof(char*) will do.
Though this is more OS or function calling convention dependent than machine dependent.
Typically the function-call conventions mirror some properties of
the machine, though. Another example where it fails is some old
(Amiga, perhaps?) 680x0-based compilers, where pointer values are
returned in register A0 while integer values are returned in D0.
Amusingly enough, this entire thread resulted from using a machine
on which this occurred. The subject line -- "AMD opteron 64" --
names a machine that "does this", i.e., returns an int in a
different (sub)register than it returns pointers. This particular
AMD is being used in 64-bit mode, so that its "int"s are 32 bits
while its pointers are 64 bits.
The original poster failed to #include <stdlib.h>, then wrote a
call to malloc() that included a cast, and as a consequence, his
code compiled without diagnostics on one machine (32-bit x86) but
with a diagnostic on another (AMD in 64-bit mode). His question
was about the diagnostic. Had the O.P. avoided the cast -- as is
the usual comp.lang.c recommendation -- he would have gotten
diagnostics on both machines. Whether this would have led him to
the correct fix -- "#include <stdlib.h>" -- is not obvious, but it
would at least have elimininated one puzzling difference.
Although I do not have hard numbers, it is clear to me that,
statistically, many more people run into trouble by casting the
return value of malloc() than by not doing so. Casting malloc()
is a bit like smoking cigarettes: many will do so without ever
dying of lung cancer, but it is still a bad habit and a poor choice
of action.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
"E. Robert Tisdale" wrote: Barry Schwarz wrote:
On a machine where the method of returning a pointer differs from the method of returning an int (such as using a different register),
Please tell us which machine does this.
Inasmuch as we try to write strictly portable code here, let us
conjugate some verbs:
I don't care We don't care
You don't care You (-all) don't care
He doesn't care They don't care
I am a Troll We are Trolls
You are a Troll You (-all) are Trolls
Trollsdale is a Troll Most Trollsdales are Trolls.
If you don't live in the southern US elide (-all). However,
looked on dispassionately , it serves a useful grammatical function
:-). I fail to find an equivalent use for ERT.
--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
In article <bq**********@e lf.torek.net> Chris Torek <no****@torek.n et> writes: [On mis-declaring malloc() and having code fail, in answer to "where might this happen"] Barry Schwarz wrote: On a machine where the method of returning a pointer differs from the method of returning an int (such as using a different register), E. Robert Tisdale wrote: Please tell us which machine does this.
.... Typically the function-call conventions mirror some properties of the machine, though. Another example where it fails is some old (Amiga, perhaps?) 680x0-based compilers, where pointer values are returned in register A0 while integer values are returned in D0.
It was for certain on a Mac. Pointers in A0, integers in D0.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
E. Robert Tisdale wrote: Dan Pop wrote:
E. Robert Tisdale writes:
Barry Schwarz wrote:
On a machine where the method of returning a pointer differs from the method of returning an int (such as using a different register),
Please tell us which machine does this.
The x86 in certain memory models where an int is 16 bits and a pointer is 32 bits.
Could you please code up an example and run it on the machine that you reference above so that we can see how it fails?
How lazy can you get?
In <3F************ @jpl.nasa.gov> "E. Robert Tisdale" <E.************ **@jpl.nasa.gov > writes: Dan Pop wrote:
E. Robert Tisdale writes:
Barry Schwarz wrote:
On a machine where the method of returning a pointer differs from the method of returning an int (such as using a different register),
Please tell us which machine does this.
The x86 in certain memory models where an int is 16 bits and a pointer is 32 bits.
Could you please code up an example and run it on the machine that you reference above so that we can see how it fails?
Yes, I can, but it shouldn't be necessary: only an idiot couldn't
figure out how it fails.
H:\>type good.c
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *p = malloc(10);
printf("%p\n", (void *)p);
return 0;
}
H:\>tcc -mh good.c
Turbo C++ Version 1.01 Copyright (c) 1990 Borland International
good.c:
Turbo Link Version 3.01 Copyright (c) 1987, 1990 Borland International
Available memory 410832
H:\>good
0856:0004
H:\>type bad.c
#include <stdio.h>
int main()
{
char *p = (char *)malloc(10);
printf("%p\n", (void *)p);
return 0;
}
H:\>tcc -mh bad.c
Turbo C++ Version 1.01 Copyright (c) 1990 Borland International
bad.c:
Turbo Link Version 3.01 Copyright (c) 1987, 1990 Borland International
Available memory 418000
H:\>bad
0000:0004
The address printed by the bad program is right into the interrupt
vector area of the processor, therefore it is clearly not the address
returned by malloc. If the bad program actually attempted to write
something into it, the whole system would get screwed.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Dan Pop wrote: E. Robert Tisdale writes:
Dan Pop wrote:
E. Robert Tisdale writes:
Barry Schwarz wrote:
>On a machine where the method of returning a pointer >differs from the method of returning an int >(such as using a different register),
Please tell us which machine does this.
The x86 in certain memory models where an int is 16 bits and a pointer is 32 bits.
Could you please code up an example and run it on the machine that you reference above so that we can see how it fails?
Yes, I can, but it shouldn't be necessary: only an idiot couldn't figure out how it fails.
H:\>type good.c #include <stdio.h> #include <stdlib.h>
int main(int argc, char* argv[]) { char *p = malloc(10); printf("%p\n", (void *)p); return 0; }
H:\>tcc -mh good.c Turbo C++ Version 1.01 Copyright (c) 1990 Borland International good.c: Turbo Link Version 3.01 Copyright (c) 1987, 1990 Borland International
Available memory 410832
H:\>good 0856:0004
H:\>type bad.c #include <stdio.h>
int main(int argc, char* argv[]) { char *p = (char *)malloc(10); printf("%p\n", (void *)p); return 0; }
H:\>tcc -mh bad.c Turbo C++ Version 1.01 Copyright (c) 1990 Borland International bad.c: Turbo Link Version 3.01 Copyright (c) 1987, 1990 Borland International
Available memory 418000
H:\>bad 0000:0004
The address printed by the bad program is right into the interrupt vector area of the processor, therefore it is clearly not the address returned by malloc. If the bad program actually attempted to write something into it, the whole system would get screwed.
Thanks Dan. I knew you could do it.
The only problem is that your example is for a C++ compiler (Turbo C++)
which is obsolete, which never fully complied
with the ANSI/ISO C89 standard much less the ANSI/ISO C99 standard
and which was designed to emit code for Intel 80286 processors.
There are almost no C programmers who actually consider it
a viable target for their applications -- nobody cares.
The point is that
1. a good C compiler will warn the programmer
if malloc has not been declared properly and
2. the code will probably execute properly
even if malloc has not been declared properly.
Omitting the type cast for the result returned by malloc
does *nothing* for the programmer except to produce
a cryptic and, possibly, misleading diagnostic
when malloc has not been declared properly.
"E. Robert Tisdale" wrote: Thanks Dan. I knew you could do it.
The only problem is that your example is for a C++ compiler (Turbo C++) which is obsolete, which never fully complied with the ANSI/ISO C89 standard much less the ANSI/ISO C99 standard and which was designed to emit code for Intel 80286 processors. There are almost no C programmers who actually consider it a viable target for their applications -- nobody cares.
Awfully critical of work someone else did at your
request and without reward ...
The point is that
1. a good C compiler will warn the programmer if malloc has not been declared properly and
True. In fact, a C99-conforming compiler *must*
complain if malloc() or any other function is used
without a prior declaration.
2. the code will probably execute properly even if malloc has not been declared properly.
False, as Dan's example demonstrated. False, false,
false. What part of "false" are you having trouble with?
Omitting the type cast for the result returned by malloc does *nothing* for the programmer except to produce a cryptic and, possibly, misleading diagnostic when malloc has not been declared properly.
A cryptic and possibly misleading diagnostic is more
helpful than no diagnostic at all. In fact, this entire
thread stems from an incident in which the unnecessary
cast hid the diagnostic the compiler would otherwise
have been required to produce! The O.P.'s mistake in
omitting <stdlib.h> went unnoticed, exactly as we've all
said would happen.
So omitting the cast is demonstrably helpful, with
this thread as the demonstration. What benefit does
*inserting* the unnecessary cast provide? None! None,
none, none. What part of "none" are you having trouble
with?
Y'know, if one cast is good, perhaps more would be
even better:
struct foo *p = (struct foo *)(uintptr_t)(c onst void *)
(intptr_t)(char **)malloc((size _t)sizeof(struc t foo));
if (0 != ((p == (struct foo*)NULL) == (int)1)) {
(void)perror ((const char*)"malloc failed!");
(void)exit ((int)EXIT_FAIL URE);
}
-- Er*********@sun .com
"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > writes:
[snip] Thanks Dan. I knew you could do it.
The only problem is that your example is for a C++ compiler (Turbo C++) which is obsolete, which never fully complied with the ANSI/ISO C89 standard much less the ANSI/ISO C99 standard and which was designed to emit code for Intel 80286 processors. There are almost no C programmers who actually consider it a viable target for their applications -- nobody cares.
As I mentioned in this thread, I posted an example myself (for gcc
under IA-64 Linux) some time ago. Since you seem disinclined to
search for it yourself, here's the Google Groups URL: http://groups.google.com/gr*********...***@cts.com%3E
I posted it about 6 weeks ago in the "why still use C?" thread. You
may have missed it the first time around; I see that you didn't
participate in the thread after that.
And of course the article that started this thread was yet another
perfectly valid example of the problem you keep telling us nobody
cares about.
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
(Note new e-mail address)
Eric Sosman <Er*********@su n.com> writes: "E. Robert Tisdale" wrote: 2. the code will probably execute properly even if malloc has not been declared properly.
False, as Dan's example demonstrated. False, false, false. What part of "false" are you having trouble with?
Why are you arguing with a troll? This is ERT's modus operandi:
he makes an incorrect statement and when people show that he is
wrong, he denies their evidence. Don't bothe
--
int main(void){char p[]="ABCDEFGHIJKLM NOPQRSTUVWXYZab cdefghijklmnopq rstuvwxyz.\
\n",*q="kl BIcNBFr.NKEzjwC IxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+= strchr(p,*q++)-p;if(i>=(int)si zeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;} This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: jacob nikom |
last post by:
Hi,
We ran MySQL (4.0.15-standard, 64-bit, SuSe 8.0) benchmarks
on 2 CPU and 4 CPU Opteron machines. Mostly we tested insertion
times with many simultaneous connections (hundreds). To our
surprise we did not find significant differences.
Each of our servers (2 and 4 CPU machine) has one 1Gbit network
connection. I have feelings that the machines are the network
bounded, not the CPU bounded. Could it be true? How to verify it?
|
by: Plymouth Acclaim |
last post by:
Hi guys,
We have a problem with Dual AMD64 Opteron/MySQL 4.0.18/Mandrake 10
for a very high volume site. We are evaluating the performance on our
new server AMD64 and it seems it's slow compared to Dual Xeon/MySQL
4.0.15/RedHat8 and Dual Xeon/MySQL 4.0.18/Mandrake 10.
And it seems there are zombie threads. 570 threads in 1 hour and we
didn't even use JDBC connection pooling at all. These threads are
supposed to be gone within 60...
|
by: Rajrup Banerjee |
last post by:
Hi,
Does anybody know what are the changes to be done
to compile C++ code which uses stl from SGI STL library,
using g++ 3.2.3, on Linux running on AMD Opteron 64 bit?
Regards,
Rajrup.
|
by: louis_pastorik |
last post by:
Does anyone have any information about 64 bit python support for Xeon
and Opteron architectures on Windows platforms? If anyone has built the
python runtime on either of these platforms before I would be really
interested. Thanks.
|
by: Ericson Smith |
last post by:
Hi,
We're thinking of moving to a 64 bit platform for our database. Does
anyone have any stories of migration from 32 bit to 64 bits?
* How did it impact performance?
* Were there any gochas?
* What processors were used (any AMD Opteron's so far?)
Also what kind of performance increase could we expect if we moved from
a dual 32 bit to a quad 32 bit platform. (We are already using speedy
| |
by: J.Haan |
last post by:
Hi all,
at the company where I work, we're planning on installing DB2 on an AMD
Opteron with 32GB of memory.
Let's say we're running DB2 8.1 FP 7 in 64bit mode on SuSE Linux
Enterprise Server 9.0. Can we create bufferpools with a size over
4GB? Let's say 12GB?
Has anyone got any experience running such a configuration?
|
by: ashokrathi |
last post by:
I am trying to compile SQL procedures on Linux running on AMD/Opteron
64-bit machine. I have 'gcc', 'cc' and 'g++' compilers on my machine. I
have set DB2_SQLROUTINE_COMPILE_COMMAND with various options, such as,
db2set DB2_SQLROUTINE_COMPILE_COMMAND="gcc -fPIC -$HOME/sqllib/include
SQLROUTINE_FILENAME.c -shared -o SQLROUTINE_FILENAME -L$HOME/sqllib/lib
-ldb2"
I have tried with/without "-fPIC" option. Without "-fPIC", I get
following...
|
by: Rocael Hernandez |
last post by:
Hello all,
I was wondering what's best for PG, since we have to
decide what will be the new server for our DB, that
will serve one or more websites.
Our actual configuration is a dual xeon 2.8ghz with
4Gb ram + scsi disks, and works fine, though some
intensive insert/update processes has taken it to 100%
cpu use.
|
by: LLessieux |
last post by:
Hi,
I have been seeing a strange behaviour when doing some tests on a Dual -
Dual Core Opteron system using Windows XP (32bits with SP2).
In out application we have a wrapper around the thread pool to handle the
work on renderers and CPU intensive tasks. On the Dual - Dual Core Opteron,
the application is correctly starting 4 threads but it seems to be running
only 2 concurrently.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |