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=- 54 3580
Lionel Valero <li***********@ polymtl.ca> writes: main (argc, argv) int argc; char *argv[]; { int *ka; int nka;
/* allocation dynamique entiere */ ka = (int *) malloc(nka * sizeof(int));
I don't recommend casting the return value of malloc():
* The cast is not required in ANSI C.
* Casting its return value can mask a failure to #include
<stdlib.h>, which leads to undefined behavior.
* If you cast to the wrong type by accident, odd failures can
result.
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 *x = malloc (sizeof (int) * 128); /* Don't do this! */
Instead, write it this way:
int *x = malloc (sizeof *x * 128);
There's a few reasons to do it this way:
* If you ever change the type that `x' points to, it's not
necessary to change the malloc() call as well.
This is more of a problem in a large program, but it's still
convenient in a small one.
* Taking the size of an object makes writing the statement
less error-prone. You can verify that the sizeof syntax is
correct without having to look at the declaration.
--
char a[]="\n .CJacehknorstu" ;int putchar(int);in t main(void){unsi gned long b[]
={0x67dffdff,0x 9aa9aa6a,0xa77f fda9,0x7da6aa6a ,0xa67f6aaa,0xa a9aa9f6,0x1f6}, *p=
b,x,i=24;for(;p +=!*p;*p/=4)switch(x=*p& 3)case 0:{return 0;for(p--;i--;i--)case
2:{i++;if(1)bre ak;else default:continu e;if(0)case 1:putchar(a[i&15]);break;}}}
In article <nE************ *******@charlie .risq.qc.ca>, li***********@p olymtl.ca says... 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 ?
At a quick glance, you seem to have left out a proper header for malloc.
The compiler doesn't automagically know what "malloc" means without one.
Also, the cast is not required in C, and helps to hide this omission from
you, thereby making it harder to diagnose.
--
Randy Howard _o
2reply remove FOOBAR \<,
_______________ _______()/ ()_____________ _______________ _______________ ___
SCO Spam-magnet: po********@sco. com
> ka = (int *) malloc(nka * sizeof(int));
No cast.
Also, sizeof( void* ) might not equal sizeof( int* ).
--
The designer of the experimental, SMP and HyperThread friendly, AppCore
library. http://AppCore.home.comcast.net
On Mon, 01 Dec 2003 18:21:07 GMT, 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)); 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 ?
Yes. You neglected to
#include <stdlib.h>
which defines the malloc() function's return value.
Since you did not do this, the compiler assumed that malloc() returned the
default type (int), and saw that you forced a conversion from (int) to (int *)
in your code. The compiler issued the warning based on this.
The fix is to
a) include <stdlib.h> in your code, and
b) remove the unnecessary case of malloc()'s return value.
--
Lew Pitcher
IT Consultant, Enterprise Technology Solutions
Toronto Dominion Bank Financial Group
(Opinions expressed are my own, not my employers')
I forgto the headers :
#include <stdio.h>
#include <sys/types.h>
#include <time.h>
Lionel Valero 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)); 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=-
In article <6d************ *******@charlie .risq.qc.ca>, li***********@p olymtl.ca says... I forgto the headers : #include <stdio.h> #include <sys/types.h> #include <time.h>
<sys/types.h> does not seem to be necessary for what you have below
and you will find out that it isn't portable either.
<time.h> also does not seem to be necessary, but at least is standard.
What is necessary: <stdlib.h>, as has been pointed out already in this
thread.
Lionel Valero 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)); 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.
--
Randy Howard _o
2reply remove FOOBAR \<,
_______________ _______()/ ()_____________ _______________ _______________ ___
SCO Spam-magnet: po********@sco. com
On Mon, 1 Dec 2003 19:00:18 UTC, Lionel Valero
<li***********@ polymtl.ca> wrote: I forgto the headers : #include <stdio.h> #include <sys/types.h> #include <time.h>
You forgot to include stdlib.h again Lionel Valero wrote: ka = (int *) malloc(nka * sizeof(int));
And this cast hides the error that you forgot to include the header in
redhat linux.
Casting the result from a function that returns void* is always an
error.
--
Tschau/Bye
Herbert
To buy eComStation 1.1 in germany visit http://www.pc-rosenau.de
Lionel Valero wrote: I have a test program that is compiled fine on a 32 bits redhat linux using gcc : ***************
cat malloc.c
#include <stdlib.h>
#include <stdio.h>
int main (int argc, char* argv[]) {
int nka = atoi(argv[1]);
/* allocation dynamique entiere */
int* ka = (int*)malloc(nk a*sizeof(int));
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
*************** ********
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?
You need to include stdlib.h which declares malloc.
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.
* If you cast to the wrong type by accident, odd failures can result.
Can you show us an 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));
This is more of a problem in a large program but it's still convenient in a small one.
* Taking the size of an object makes writing the statement less error-prone. You can verify that the sizeof syntax is correct without having to look at the declaration. 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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
| |
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: 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...
|
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: 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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |