473,770 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

AMD opteron 64

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 3590
"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > wrote in message
news:3F******** ******@jpl.nasa .gov...
Ben Pfaff wrote:
I don't recommend casting the return value of malloc():

* The cast is not required in ANSI C.
But an ANSI/ISO C++ compiler will complain.


So what? This is comp.lang.c.

* Casting its return value can mask a failure to
#include <stdlib.h>, which leads to undefined behavior.
No! It may mask the fact that malloc was not declared
but a good C compiler will warn you about that.


It might, but it's not required to. I'd rather rely upon
accurate knowledge than depend upon a convenience feature
of a tool, which might or might not exist.
* If you cast to the wrong type by accident,
odd failures can result.
Can you show us an example?


The OP's original message is a perfect example.
In fact, the second problem is your problem here. Fix it.

When calling malloc(), I recommend using the sizeof operator on
the object you are allocating, not on the type. For instance,
*don't* write this:

int *p = malloc (sizeof (int) * 128); /* Don't do this! */

Instead, write it this way:

int *p = malloc (sizeof *p * 128);

There's a few reasons to do it this way:

* If you ever change the type that `p' points to, it's not
necessary to change the malloc() call as well.


A better solution would be:

typedef int T;
T* p = (T*)malloc(128* sizeof(T));


Casting the return value from malloc() is never 'better'.
And your typdef only obfuscates things.
-Mike
Nov 13 '05 #11
"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > writes:
Ben Pfaff wrote:
I don't recommend casting the return value of malloc():
* The cast is not required in ANSI C.


But an ANSI/ISO C++ compiler will complain.


Fortunately, we are not discussing C++. malloc() should not
normally be used in C++.
* Casting its return value can mask a failure to
#include <stdlib.h>, which leads to undefined behavior.


No! It may mask the fact that malloc was not declared
but a good C compiler will warn you about that.


This is in fact the OP's problem, so I don't see how you can
discount it.
* If you cast to the wrong type by accident,
odd failures can result.


Can you show us an example?


Casting to (char) instead of (char *) is bound to be a problem.
In fact, the second problem is your problem here. Fix it.
When calling malloc(), I recommend using the sizeof operator on
the object you are allocating, not on the type. For instance,
*don't* write this:
int *p = malloc (sizeof (int) * 128); /* Don't do this! */
Instead, write it this way:
int *p = malloc (sizeof *p * 128);
There's a few reasons to do it this way:
* If you ever change the type that `p' points to, it's not
necessary to change the malloc() call as well.


A better solution would be:

typedef int T;
T* p = (T*)malloc(128* sizeof(T));


I don't see how that's a better solution at all.
--
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;}
Nov 13 '05 #12
"E. Robert Tisdale" wrote:

Ben Pfaff wrote:
I don't recommend casting the return value of malloc():

* The cast is not required in ANSI C.


But an ANSI/ISO C++ compiler will complain.


A COBOL compiler will complain even louder. So what?

--
Er*********@sun .com
Nov 13 '05 #13
On Mon, 01 Dec 2003 18:21:07 GMT, in comp.lang.c , Lionel Valero
<li***********@ polymtl.ca> wrote:
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));


Everyone else has explained your immediate problem.forgett ing

HoweverI notice you are using nka to size your array. But you didn't
initialise it to any value. So it contains garbage, and may crash your
program.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.c om/ms3/bchambless0/welcome_to_clc. html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 13 '05 #14
Eric Sosman <Er*********@su n.com> scribbled the following:
"E. Robert Tisdale" wrote:
Ben Pfaff wrote:
> I don't recommend casting the return value of malloc():
>
> * The cast is not required in ANSI C.
But an ANSI/ISO C++ compiler will complain.

A COBOL compiler will complain even louder. So what?


ERT seems to have a fascination with compiling C code with a C++
compiler these days. Can you say "one-trick pony", ERT?

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
Nov 13 '05 #15
On Mon, 01 Dec 2003 13:07:09 -0800, "E. Robert Tisdale"
<E.************ **@jpl.nasa.gov > wrote in comp.lang.c:
Lionel Valero wrote:
I have a test program
that is compiled fine on a 32 bits redhat linux using gcc :
***************
Still playing the fool I see, Tisdale.
> cat malloc.c #include <stdlib.h>
#include <stdio.h>

int main (int argc, char* argv[]) {
int nka = atoi(argv[1]);


What happens when you run it without command line arguments and
dereference the null pointer? Can you say "segfault"?
/* allocation dynamique entiere */
int* ka = (int*)malloc(nk a*sizeof(int));
About one in 20 times you actually post something of value. Sadly,
this is not one of those times...

int *ka = malloc(nka * sizeof *ka);

Note the pleasing symmetry of the dual asterisks.
if (NULL == ka) {
fprintf(stderr, "<ERROR>: Out of free storage (malloc)!\n");
fprintf(stderr, "<ERROR>: %d int words required\n", nka);
exit (EXIT_FAILURE);
}
return EXIT_SUCCESS;
}
> gcc -Wall -std=c99 -pedantic -o malloc malloc.c
> ./malloc 13
> ./malloc 999999999999

<ERROR>: Out of free storage (malloc)!
<ERROR>: 2147483647 int words required


Why didn't you show the results of running:

./malloc

???

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 13 '05 #16
*** topposting fixed ***

Lionel Valero wrote:
Lionel Valero wrote:
I have a test program that is compiled fine on a 32 bits redhat linux
using gcc :
*************** ********
main (argc, argv)
int argc;
char *argv[];
Do not use old fashioned function declarations, they have been
obsolete for at least 15 years. main returns int, say so.
{
int *ka;
int nka;

/* allocation dynamique entiere */
ka = (int *) malloc(nka * sizeof(int));
Do not cast malloc results. nka is uninitialized. Use sizeof
*ka.
if (!ka) {
printf ("<ERROR> : Out of heap space (malloc) !\n");
printf ("<ERROR> : %d int words required\n", nka);
exit (-1);
-1 is not a portable value here. EXIT_FAILURE and
EXIT_SUCCESS come to mind, after #including <stdlib.h>
}
}
*************** ********

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 ?

Increase the gcc warning levels. -W -Wall -ansi -pedantic -O1 are
the recommended minimum.

I forgto the headers :
#include <stdio.h>
#include <sys/types.h>
This is not a valid ISO C header. Omit it.
#include <time.h>


This is not used. omit it.

Please Do Not Toppost.

--
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!
Nov 13 '05 #17
"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > writes:
Ben Pfaff wrote:
I don't recommend casting the return value of malloc():
* The cast is not required in ANSI C.


But an ANSI/ISO C++ compiler will complain.


So don't use a C++ compiler on C source (or a Fortran compiler, or an
Intercal compiler). There's no good reason C source code should be
constrained to be valid C++.

<OT>
Well-written C++ code doesn't use malloc() anyway; it uses the "new"
operator.
</OT>

--
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)
Nov 13 '05 #18
On Mon, 01 Dec 2003 13:20:48 -0800, "E. Robert Tisdale"
<E.************ **@jpl.nasa.gov > wrote:
Ben Pfaff wrote:
I don't recommend casting the return value of malloc():

* The cast is not required in ANSI C.


But an ANSI/ISO C++ compiler will complain.
* Casting its return value can mask a failure to
#include <stdlib.h>, which leads to undefined behavior.


No! It may mask the fact that malloc was not declared
but a good C compiler will warn you about that.


On a machine where the method of returning a pointer differs from the
method of returning an int (such as using a different register), the
behavior is indeed undefined. malloc will return the pointer using
the correct procedure. The compiler will generate code to convert the
assumed returned int. Since malloc did not return an int, this code
will operate on residual data.
<<Remove the del for email>>
Nov 13 '05 #19
Joona I Palaste <pa*****@cc.hel sinki.fi> wrote:
Eric Sosman <Er*********@su n.com> scribbled the following:
"E. Robert Tisdale" wrote:
Ben Pfaff wrote:
> I don't recommend casting the return value of malloc():
>
> * The cast is not required in ANSI C.

But an ANSI/ISO C++ compiler will complain.

Which proves once again that C++ is broken, since the cast is useless
and useless casts should be anathema.
A COBOL compiler will complain even louder. So what?


ERT seems to have a fascination with compiling C code with a C++
compiler these days.


That's because ERT has, and AFAICT has always had, a bee in his bonnet
about C++ being "the new C". Not even Bjarne Stroustrup has that
delusion, but some people are impossible to disconfuse.

Richard
Nov 13 '05 #20

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

Similar topics

0
1430
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?
0
519
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...
1
1446
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.
1
1876
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.
1
2333
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
0
1222
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?
3
2264
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...
1
1545
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.
4
2340
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.
0
10260
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
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,...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7456
isladogs
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...
0
5354
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...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
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...

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.