如何使用read()系统调用来读取32位整数 [英] How to use read() system call to read an 32bit integer

查看:100
本文介绍了如何使用read()系统调用来读取32位整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,所有


也许这个问题不适合发布在这里:(但无论如何会

有人帮助我吗?


我正在做我的操作系统作业。我知道如何使用缓冲区

字符串来做读写。


但是如何大约32位int?


这是我的方法:


typedef unsigned char * byte_pointer;

write(fd,(byte_pointer)& i,sizeof(int));

read(fd,(byte_pointer)& j,sizeof(int));


它有效。


我不知道我的方法是否是一种常见的方法。或者还有一些其他的

方式要做到这一点。

提前感谢。

解决方案

文章< 11 **** ******************@r34g2000hsd.googlegroups .com> ;,

Yin Zhu< zh ******** @ gmail。 comwrote:


>你好,所有

也许这个问题不适合发布她e :(但无论如何会有人帮助我吗?

我正在做我的操作系统功课。我知道如何使用缓冲区
字符串来进行读写。

但32位int怎么样?

这是我的方法:

typedef unsigned char * byte_pointer;
write(fd,(byte_pointer)& i,sizeof(int));
read(fd,(byte_pointer)& j,sizeof (INT));



非主题。不便携。不能在这里讨论它。 Blah,等等,等等。


-

有用的clc相关链接:

http://en.wikipedia.org/wiki/Aspergers
http://en.wikipedia.org/wiki/Clique
http://en.wikipedia.org/wiki/C_programming_language


Yin Zhu写道:


你好,所有


也许这个问题不是适当发布在这里:(但无论如何会

有人帮助我吗?


我正在做我的操作系统作业。我知道如何使用缓冲区

字符串做读写。


但32位int怎么样?


这是我的方法执行:


typedef unsigned char * byte_pointer;

write(f d,(byte_pointer)& i,sizeof(int));

读取(fd,(byte_pointer)& j,sizeof(int));


它有效。


我不知道我的方法是否是一种常见方式。或者还有一些其他

的方法。


提前感谢。



在标准C中你会使用fread和fwrite而不是读写。

但是请不要忘记:


如果它有效,它就可以了。不要修复那些没有被打破的东西


9月11日晚上9:11,jacob navia< ja ... @ jacob.remcomp .frwrote:


Yin Zhu写道:


你好,所有


也许这个问题不适合发布在这里:(但无论如何会

有人帮我吗?


我正在做我的操作系统作业。我知道如何使用缓冲区

字符串来进行读写。


但32位int怎么样?


这是我的方法:


typedef unsigned char * byte_pointer;

write(fd,(byte_pointer)& i,sizeof(int));

read(fd,(byte_pointer)& j,sizeof(int));


它有效。


我不知道我的方法是否是常用方法。或者还有其他一些方法可以做到这一点。


提前感谢。



在标准C中你会使用fread和fwrite而不是读写。

但请不要忘记:


如果有效,它可以工作。不要修复那些没有破坏的东西



但我需要将fread与read进行比较。

fread有自己的缓冲机制,我想写一个缓冲读取

与fread进行比较。


Hello, All

Maybe this question is not proper to post here:( but anyway would
someone help me?

I am doing my operating system homework. I know how to use a buffer
string to do read and write.

But how about 32-bit int?

Here is my method to do:

typedef unsigned char *byte_pointer;
write(fd, (byte_pointer)&i, sizeof(int));
read(fd, (byte_pointer)&j, sizeof(int));

it works.

I don''t know whether my method is a common way. or there''s some other
ways to do it.
thanks in advance.

解决方案

In article <11**********************@r34g2000hsd.googlegroups .com>,
Yin Zhu <zh********@gmail.comwrote:

>Hello, All

Maybe this question is not proper to post here:( but anyway would
someone help me?

I am doing my operating system homework. I know how to use a buffer
string to do read and write.

But how about 32-bit int?

Here is my method to do:

typedef unsigned char *byte_pointer;
write(fd, (byte_pointer)&i, sizeof(int));
read(fd, (byte_pointer)&j, sizeof(int));

Off topic. Not portable. Cant discuss it here. Blah, blah, blah.

--
Useful clc-related links:

http://en.wikipedia.org/wiki/Aspergers
http://en.wikipedia.org/wiki/Clique
http://en.wikipedia.org/wiki/C_programming_language


Yin Zhu wrote:

Hello, All

Maybe this question is not proper to post here:( but anyway would
someone help me?

I am doing my operating system homework. I know how to use a buffer
string to do read and write.

But how about 32-bit int?

Here is my method to do:

typedef unsigned char *byte_pointer;
write(fd, (byte_pointer)&i, sizeof(int));
read(fd, (byte_pointer)&j, sizeof(int));

it works.

I don''t know whether my method is a common way. or there''s some other
ways to do it.
thanks in advance.

In standard C you would use fread and fwrite instead of read and write.
But please do not forget:

If it works, it works. Do not fix something that''s not broken


On Sep 11, 9:11 pm, jacob navia <ja...@jacob.remcomp.frwrote:

Yin Zhu wrote:

Hello, All

Maybe this question is not proper to post here:( but anyway would
someone help me?

I am doing my operating system homework. I know how to use a buffer
string to do read and write.

But how about 32-bit int?

Here is my method to do:

typedef unsigned char *byte_pointer;
write(fd, (byte_pointer)&i, sizeof(int));
read(fd, (byte_pointer)&j, sizeof(int));

it works.

I don''t know whether my method is a common way. or there''s some other
ways to do it.

thanks in advance.


In standard C you would use fread and fwrite instead of read and write.
But please do not forget:

If it works, it works. Do not fix something that''s not broken


but I need to compare fread with read.
fread has its own buffering mechanism, I want to write a buffered read
to compare with fread.


这篇关于如何使用read()系统调用来读取32位整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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