AMD opteron 64 [英] AMD opteron 64

查看:54
本文介绍了AMD opteron 64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我有一个测试程序,使用gcc在32位redhat linux上编译正常:

******* ****************

main(argc,argv)

int argc;

char * argv [];

{

int * ka;

int nka;


/ *分配动力entiere * /

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

if(!ka){

printf("< ERROR>:超出堆空间(malloc)!\ n");

printf("< ERROR>:%d int words required are\
" ;,nka);

退出(-1);

}

}

***** ******************


但是在linux下使用AMD opteron 64,我从编译器得到这条消息:


警告:从不同大小的整数转换为指针


任何解释?


问候,
Lionel。

-

- = O = --------------------- --------------------- = O = -

Lio nelValéro

AnalysteInformatiqueDépartementGénieChimique
$ b $bécolePolytechniquedeMontréal

C.P. 6079,succ。 center-ville

蒙特利尔(魁北克)H3C 3A7

电话:(514)340 - 4711#4805 / C552

传真:(514) 340 - 4159

- = O = ----------------------------------- ------- = O = -

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=-

推荐答案

Lionel Valero< li ********* **@polymtl.ca>写道:
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));
main (argc, argv)
int argc;
char *argv[];
{
int *ka;
int nka;

/* allocation dynamique entiere */
ka = (int *) malloc(nka * sizeof(int));




我不建议转换malloc()的返回值:


* ANSI C中不需要强制转换。


*转换它的返回值可以掩盖#include

< stdlib.h>的失败,这会导致未定义的行为。


*如果你偶然输入了错误的类型,奇怪的失败可能会导致
结果。


实际上,第二个问题是你的问题。修复它。


调用malloc()时,我建议在你分配的对象上使用sizeof运算符,而不是在类型上。例如,

*不要写这个:


int * x = malloc(sizeof(int)* 128); / *不要这样做! * /


相反,请这样写:


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


这样做有几个理由:


*如果你改变了'x'指向的类型,它'''更改malloc()调用也不需要



这在大型程序中更是一个问题,但它仍然是

方便小一点。


*考虑一个对象的大小使得编写语句

不易出错。您无需查看声明就可以验证sizeof语法是否正确。


-

char a [ ] =" \ n .CJacehknorstu" ;; int putchar(int); int main(void){unsigned long b []

= {0x67dffdff,0x9aa9aa6a,0xa77ffda9,0x7da6aa6a,0xa6 7f6aaa,0xaa9aa9f6 ,0x1f6},* p =

b,x,i = 24; for(; p + =!* p; * p / = 4)switch(x = * p& 3)case 0:{返回0; for(p - ; i - ; i - )case

2:{i ++; if(1)break; else default:continue; if(0)case 1:putchar (a [i& 15]); break;}}}



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);int main(void){unsigned long b[]
={0x67dffdff,0x9aa9aa6a,0xa77ffda9,0x7da6aa6a,0xa6 7f6aaa,0xaa9aa9f6,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)break;else default:continue;if(0)case 1:putchar(a[i&15]);break;}}}


在文章< nE **************** ***@charlie.risq.qc.ca>,
li ******* **** @ polymtl.ca 说...
In article <nE*******************@charlie.risq.qc.ca>,
li***********@polymtl.ca says...
你好,
我有一个测试程序,可以在32位redhat linux上使用gcc:
*************************
main(argc,argv)
int argc;
char * argv [];
{
int * ka;
int nka;

/ *分配动态entiere * /
ka =(int *)malloc(nka * sizeof(int));
if(!ka){
printf("< ERROR> :堆空间(malloc)!\ n");
printf("< ERROR>:%d int words required \ n",nka);
exit(-1) ;
}
}


但是在linux下suse 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 ?




快速浏览一下,你似乎已经为malloc遗漏了一个合适的标题。

编译器没有自动知道什么是malloc。意味着没有一个。

另外,C中不需要演员表,并且有助于隐藏这个遗漏,从而使你更难诊断。


-

Randy Howard _o

2reply删除FOOBAR \<,

______________________()/( )______________________________________________

SCO Spam-magnet: po********@sco.com


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


无演员。


此外,sizeof(void *)可能不等于sizeof(int *)。


-

实验设计师,SMP和HyperThread友好,AppCore

library。

http://AppCore.home.comcast.net
> 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


这篇关于AMD opteron 64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆