Printf 不替换格式字符串参数
我正在尝试做一个涉及修改 minix 中的一些内核代码的家庭作业,但我遇到了我见过的最奇怪的问题。
我正在 pm 服务器上修改 alloc.c (对于那些熟悉 minix 的人来说),并且我在文件顶部添加了一个全局变量:
PUBLIC int logging = 0;
然后稍后我尝试在我的服务器之一中读取该变量我添加到内核的函数:
PUBLIC int do_setalloc(void)
{
printf("logging = %i\n", logging");
return (OK);
}
然后我有一个测试程序,它在内核空间之外运行此代码:
int main(void)
{
message m;
m.m1_i1 = 1;
m.m1_i2 = 1;
_syscall(MM,69,&m);
return 0;
}
这是运行此代码时的输出:
logging = %i
Printf 实际上并未用 %i 的实际值替换 %i 格式整数,我在这里抓狂,这项作业很快就要到期了!帮助!
I'm trying to do a homework assignment involving modifying some kernel code in minix and i'm having the strangest issue i've ever seen.
I'm modifying alloc.c on the pm server (for those of you familiar with minix) and i've added a global variable to the top of the file:
PUBLIC int logging = 0;
Then later on i'm trying to read the variable in one of my functions i've added to the kernel:
PUBLIC int do_setalloc(void)
{
printf("logging = %i\n", logging");
return (OK);
}
I then have a test program which runs this code outside the kernel space:
int main(void)
{
message m;
m.m1_i1 = 1;
m.m1_i2 = 1;
_syscall(MM,69,&m);
return 0;
}
This is the output when this code gets run:
logging = %i
Printf isn't actually replacing the %i formatting with the actual value of the integer, I am tearing my hair out here and this assignment is due soon! Help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不认为“%i”是有效的格式转换;打印 int 时最常用的标签是“%d”。但我刚刚查看的 printf 手册页声称 %i 是 %d 的同义词。也许 minix printf 没有定义它。
I didn't think "%i" was a valid format conversion; the most commonly-used tag to print an int is "%d". But the printf manpage I just looked at claimed %i was a synonym for %d. Perhaps the minix printf doesn't define it.
printf 中的整数不是
%d
吗?Isn't it
%d
for an integer in printf?