在solaris中长型 [英] long type in solaris
问题描述
嗨!
我正在使用c语言。
我需要使用memcpy将长类型值复制到char字符串中
函数:
memcpy(字符串,(long *)值,len)
这个值将被插入到数据库中。
在Windows机器上运行良好,在Solaris上没有。窗口和
solaris到c语言的路径是一样的。
我想说的是,如果它们是真正的价值也可以正常工作
以相同的方式使用:
memcpy(字符串,(真实*)值,len)
是否有特定方式使用long值在solaris上?
或者使用长类型的memcpy?
非常感谢,我希望能够清楚。
Hi!
I''m using c language.
I need to copy a long type value into a char string using a memcpy
function:
memcpy(string, (long *) value, len)
this value will be then insert into a database.
On windows machine it works well, on Solaris not. The windows and
solaris path into c language is the same.
I''d like to say also that real value works correctly also if they are
used in the same manner:
memcpy(string, (real *) value, len)
Is there a particular manner to use long values on solaris?
Or to use memcpy with long types?
Thank you very much, I hope to be clear.
推荐答案
si ********* @ googlemail.com 写道:
嗨!
我正在使用c语言。
我需要使用memcpy
函数将长类型值复制到char字符串中:
memcpy(string,(long *)value,len)
然后将该值插入数据库。
Hi!
I''m using c language.
I need to copy a long type value into a char string using a memcpy
function:
memcpy(string, (long *) value, len)
this value will be then insert into a database.
我不确定你希望通过将值转换为(long *)来实现什么,
你将不得不更清楚你的意图究竟是什么。
I''m not sure what you hope to achieve by casting value to (long*),
you''ll have to be more clear as to what your intentions actually are.
在Windows机器上它运行良好,在Solaris上没有。窗口和
solaris到c语言的路径是一样的。
我想说的是,如果它们是真正的价值也可以正常工作
以相同的方式使用:
memcpy(字符串,(真实*)值,len)
是否有特定方式使用long值在solaris上?
或者使用长类型的memcpy?
On windows machine it works well, on Solaris not. The windows and
solaris path into c language is the same.
I''d like to say also that real value works correctly also if they are
used in the same manner:
memcpy(string, (real *) value, len)
Is there a particular manner to use long values on solaris?
Or to use memcpy with long types?
memcpy不关心类型,它只是复制字节。
-
Clark S. Cox III
cl*******@gmail.com
si*********@googlemail.com 写道:
si*********@googlemail.com wrote:
我正在使用c语言。
我需要将长类型值复制到char字符串中使用memcpy
函数:
I''m using c language.
I need to copy a long type value into a char string using a memcpy
function:
为什么?
why?
memcpy(string,(long *)value,len)
memcpy(string, (long *) value, len)
如果值很长,为什么要将它转换为(long *)?
我可能会这样编码: -
memcpy(字符串,& value,sizeof value);
>
然后将该值插入数据库。
在Windows机器上它运行良好,在Solaris上没有。
this value will be then insert into a database.
On windows machine it works well, on Solaris not.
什么效果不好是什么意思?
what does "not work well" mean?
windows和
solaris到c语言的路径是一样的。
我还想说,如果它们以相同的方式使用
,那么真正的价值也能正常工作:
memcpy(string,(real *)value,len )
The windows and
solaris path into c language is the same.
I''d like to say also that real value works correctly also if they are
used in the same manner:
memcpy(string, (real *) value, len)
?? "实"不是我认识的C类型。
?? "real" is not a C type I recognise.
是否有一种特殊方式在solaris上使用长值?
或者使用长类型的memcpy?
非常感谢,我希望能够清楚。
Is there a particular manner to use long values on solaris?
Or to use memcpy with long types?
Thank you very much, I hope to be clear.
没有...
可能的字节按不同的顺序排列
Windows和Solaris。所谓的endian是指所谓的endian。问题。您可能需要在写入之前重新设置字符串中的字节。
您需要解释您的问题所在。
-
Nick Keighley
上帝是真的。
除非作出相反的类型声明。
(旧的FORTRAN笑话)
well no...
Its possible the bytes are arranged in a different order between
Windows and Solaris. A so called "endian" problem. You may
have to rearrage the bytes in the string before the write.
You need to explain what your problem is.
--
Nick Keighley
GOD IS REAL.
Unless a type declaration to the contrary is made.
(old FORTRAN joke)
si ********* @ googlemail.com 写道:
si*********@googlemail.com wrote:
嗨!
我'我正在使用c语言。
我需要使用memcpy
函数将长类型值复制到char字符串中:
memcpy(string ,(long *)value,len)
然后将该值插入数据库。
Hi!
I''m using c language.
I need to copy a long type value into a char string using a memcpy
function:
memcpy(string, (long *) value, len)
this value will be then insert into a database.
这段代码几乎肯定是错的,但因为你没有向我们展示任何其他声明并使用它''''很难
说出什么,确切地说,是错误的。
我说这是错的,因为你有一个演员`(长*)值。
`value`是指针类型(即使你暗示它很长),
在这种情况下你不需要演员[1] ],或者它不是,其中
你将非指针交给`memcpy`,BOOM。
我想知道如果你的意思是'& value`?在这种情况下,再次,你不需要
需要演员[1]。
你要复制多少字节?我们不知道`len`是什么。
人们希望它是'sizeof(long)`。人们也希望
" string"位置足够长。人们希望它有足够的空间用于终止0.你显示的代码并没有把
终止为0。当然,也许一些未示出的代码可以。或者
也许是字符串不是变量的正确名称。
数据库期望的字节数是多少?是什么让你觉得
那个`len`是正确的数字,是什么让你认为
`long`就是这么宽?因为如果一个long比那个更短,那么你将会复制垃圾;如果更长,你会错过
out on some bytes,也许是最相关的[2]。
This code is almost certainly wrong, but because you haven''t
shown us any of the other declarations and uses it''s hard
to say what, exactly, is wrong.
I say it''s wrong because you have a cast `(long *) value`. Either
`value` is a pointer type (even though you imply that it''s a long),
in which case you don''t need the cast [1], or it isn''t, in which
case you''re handing a non-pointer to `memcpy`, BOOM.
I wonder if you meant `&value`? In which case, again, you don''t
need the cast [1].
How many bytes are you copying? We don''t know what `len` is.
One hopes that it''s `sizeof(long)`. One also hopes that the
"string" location is long enough. One hopes that it has enough
space for the terminating 0. The code you show doesn''t put the
terminating 0 in. Of course, maybe some unshown code does. Or
perhaps "string" isn''t the right name for the variable.
How many bytes is the database expecting? What makes you think
that `len` is the right number, and what makes you think that a
`long` is exactly that wide? Because if a `long` is shorter
than that, you''ll be copying rubbish; and if longer, you''ll miss
out on some bytes, maybe the most relevant ones [2].
在Windows机器上它运行良好,在Solaris上没有。
On windows machine it works well, on Solaris not.
你看到什么样的病态工作?
What kind of ill working do you see?
windows和solaris到c语言的路径是相同。
The windows and solaris path into c language is the same.
我不知道这意味着什么 [3]。
我怀疑你遇到了一个endianness / sizeof问题,
因为你没想到它可能是一个权利
buxxer修复。
[1]假设你已经记住#include< string.h> ;.
[2] EG如果`long`的值为'17`,则持有
`17`的字节是相关的。
[3] Bones。
-
Chris" electric hedgehog" Dollin
人们是设计的一部分。忘记这一点是危险的。 / Star Cops /
"I don''t know what that means" [3].
I suspect you''re hitting an endianness / sizeof problem,
which because you didn''t anticipate it may be a right
buxxer to fix.
[1] Assuming that you''ve remembered to #include <string.h>.
[2] EG if the `long` has the value `17`, the bytes holding the
`17` are the relevant ones.
[3] Bones.
--
Chris "electric hedgehog" Dollin
"People are part of the design. It''s dangerous to forget that." /Star Cops/
这篇关于在solaris中长型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!