本文介绍了什么是strdup回归的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 已知strdup()返回一个char *类型,但有时候 后面的代码会生成警告消息。 char * x = ... char * p = strdup(x); 你必须改变它要 char * p =(char *)strdup(x); 为什么? Hi, It''s known that strdup() returns a char* type, but sometimes thefollowing code generates warning messages. char *x = ...char *p = strdup(x); You must change it to char *p = (char*) strdup(x); why?推荐答案 strdup()在C标准中没有提及它是在一个保留的 引导名称空间;所以你不能自己定义。 所以我们对它一无所知。 strdup() isn''t mentioned in the C Standard and it''s in a reservednamespace to boot; so you can''t define it yourself.So we don''t really know anything about it. 我怀疑strdup()的范围没有原型。 string.h可能不会声明它(我不是确保它允许在conmforming模式下声明 。 你需要提出更多的实施问题 某些指导。 - Nick Keighley 服务器机房应该不友好!他们应该看起来很危险,他们应该感到非常寒冷,他们应该莫名其妙地吵闹。 如果你可以安排燃烧晶体管的气味,这很好 也是。 如果有的话,我宁愿看到设计在黑暗中的机架式服务器 预感 颜色搭配很多金属尖刺都伸出来了。 Mike Sphar(新闻// alt.sysadmin.recovery) I suspect there is no prototype in scope for strdup().string.h may not declare it (I''m not sure it''s allowed to declareit, in conmforming mode). You need to ask the question of your implementation for morecertain guidance.--Nick Keighley Server rooms should be unfriendly! They should look dangerous,they should be uncomfortably cold, they should be inexplicably noisy.If you can arrange for the smell of burning transistors, that''s goodtoo.If anything, I''d rather see rackmounted servers designed in darkforebodingcolors with lots of metal spikes sticking out of them.Mike Sphar (on news//alt.sysadmin.recovery) 因为您尚未声明strdup(),并且未包含 声明的标头。您还显然没有以某种模式运行编译器 ,它抱怨未声明的函数。 修复添加一个演员的问题在系统上不能可靠地运行 其中指针比整数长,或指针和整数的返回 约定不同。 br /> - 理查德 - 请记得提及我/你留下的录音带。 Because you have not declared strdup(), and not included a header thatdeclares it. You have also apparently not run your compiler in a modewhere it complains about undeclared functions. "Fixing" the problem by adding a cast won''t work reliably on systemswhere pointers are longer than integers, or where the returnconventions for pointers and integers are different. -- Richard--Please remember to mention me / in tapes you leave behind. strdup()在C标准中没有提及它是在保留的 $ b要启动的$ b命名空间;所以你不能自己定义它。 strdup() isn''t mentioned in the C Standard and it''s in a reservednamespace to boot; so you can''t define it yourself. 如果你不包括< string.h> You can if you don''t include <string.h> 我怀疑strdup()的范围没有原型。 string.h可能不会声明它(我不是确定它允许在conmforming模式下声明 它。 I suspect there is no prototype in scope for strdup().string.h may not declare it (I''m not sure it''s allowed to declareit, in conmforming mode). 这是允许的,因为正如你所说,strdup是实现命名空间。 It is allowed, since as you said, strdup is implementation namespace. 这篇关于什么是strdup回归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-23 01:02