endianness和sscanf / sprintf [英] endianness and sscanf/sprintf

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

问题描述

两个不同的平台通过协议进行通信,这些协议包含

函数和ascii形式的参数。系统可能很小

endian / big endian。


可以使用sprintf格式化字符串并使用

sscanf进行检索。

每个参数都有一个分隔符,数据类型大小移植到

平台,预期的参数顺序是已知的。


这种方法是否便于携带endianess?

问候,

Pramod

解决方案

" pramod" < SP ******** @ yahoo.com>在消息中写道

news:c6 ************************** @ posting.google.c om

两个不同的平台通过协议进行通信,这些协议由ascii形式的
函数和参数组成。系统可能很少/ endian / big endian。

可以使用sprintf格式化字符串并使用
sscanf进行检索。
每个参数都有一个分隔符,数据类型大小被移植到
平台,并且预期的参数顺序是已知的。

这种方法是否可移植wrt endianess?

问候,
Pramod



endianness只会影响整数的存储方式(也许

浮动点数---我不确定。它不会影响

字符的存储,因此如果您只发送文本则不会出现问题。

-

John Carson

1.要回复电子邮件地址,请删除donald

2.不要回复电子邮件地址(在此处发布)


你会很好,因为所有东西都被转换为字符。

只要字符表示为8个字节,数字

将被正确解释。 Java字节码使用相同的方法。


以下文章详细讨论了字节顺序:

http://www.eventhelix.com/RealtimeMa...ndOrdering.htm


Sandeep

-
http:// www。 EventHelix.com/EventStudio

EventStudio 2.0 - 超越UML用例和序列图


EventHelix.com写道:

你可以将所有内容转换为字符。
只要字符表示为8个字节,数字
就会被正确解释。



在C语言中(据我所知,C ++也是如此),字符总是以单字节表示

。字符/常量/用int类型表示(在C中,但不是C ++)

,可以想象为8字节。这是你的意思吗?


(后续设置为comp.lang.c)


-

Richard Heathfield: bi****@eton.powernet.co.uk

Usenet是一个奇怪的地方。 - Dennis M Ritchie,1999年7月29日。

C FAQ: http://www.eskimo.com/~scs/C-faq/top.html

K& R答案,C书等:< a rel =nofollowhref =http://users.powernet.co.uk/etontarget =_ blank> http://users.powernet.co.uk/eton

Two different platforms communicate over protocols which consist of
functions and arguments in ascii form. System might be little
endian/big endian.

It is possible to format string using sprintf and retreive it using
sscanf.
Each parameter has a delimiter, data type size is ported to the
platform, and expected argument order is known.

Is this approach portable w.r.t. endianess ?
regards,
Pramod

解决方案

"pramod" <sp********@yahoo.com> wrote in message
news:c6**************************@posting.google.c om

Two different platforms communicate over protocols which consist of
functions and arguments in ascii form. System might be little
endian/big endian.

It is possible to format string using sprintf and retreive it using
sscanf.
Each parameter has a delimiter, data type size is ported to the
platform, and expected argument order is known.

Is this approach portable w.r.t. endianess ?
regards,
Pramod


endianness only affects the way that integers are stored (and perhaps
floating point numbers --- I am not sure). It does not affect the storage of
characters so it is not an issue if you are only sending text.
--
John Carson
1. To reply to email address, remove donald
2. Don''t reply to email address (post here instead)


You will be fine as everything is being converted to characters.
As long as characters are represented as 8 bytes, the numbers
will be interpreted correctly. Java bytecodes use the same approach.

The following article discusses the endianness in detail:

http://www.eventhelix.com/RealtimeMa...ndOrdering.htm

Sandeep
--
http://www.EventHelix.com/EventStudio
EventStudio 2.0 - Go Beyond UML Use Case and Sequence Diagrams


EventHelix.com wrote:

You will be fine as everything is being converted to characters.
As long as characters are represented as 8 bytes, the numbers
will be interpreted correctly.



In C (and, as far as I am aware, C++ too), characters are always represented
in a single byte. Character /constants/ are represented (in C, but not C++)
by the int type, which might conceivably be eight bytes. Is that what you
meant?

(Followups set to comp.lang.c)

--
Richard Heathfield : bi****@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton


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

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