c - 字符串文字在传递给函数时变成空字符
问题描述
我正在制作一个简单的内核,并且遇到了将字符串文字作为char*
.
从传递给函数的字符串中打印任何字符都会导致 nullchar,我对此进行了测试,我打印了第一个 char + 48,它打印了一个 0。我不确定这可能是由于我用来编译的命令,我正在使用以下 GCC 标志进行编译-fno-stack-protector -mgeneral-regs-only -mno-red-zone -ffreestanding -fno-pie -m32 -nostdinc -nostdlib
我通过编译为程序集检查了字符串文字是否在程序集中。
主文件:
#include "../drivers/ports.h"
#include "../drivers/screen.h"
void main()
{
clear_screen();
kprint_at("hhgfhehthdtydhgf", 1, 6);
/*
kprint_at("This text spans multiple lines", 75, 10);
kprint_at("There is a line\nbreak", 0, 20);
kprint("There is a line\nbreak");
kprint_at("What happens when we run out of space?", 45, 24);
*/
}
在 screen.c 文件中
void kprint_at(char *message, int col, int row)
{
print_char(message[0] + 48, col, row, WHITE_ON_BLACK); // prints a 0 to the screen, ascii 48
int offset;
if (col >= 0 && row >= 0)
{
offset = get_offset(col, row);
}
else
{
offset = get_cursor_offset();
row = get_offset_row(offset);
col = get_offset_col(offset);
}
int i = 0;
while (message[i] != 0)
{
offset = print_char(message[i++], col, row, WHITE_ON_BLACK);
row = get_offset_row(offset);
col = get_offset_col(offset);
}
}
我已经验证了从函数调用的所有函数的正确操作kprint_at
。
解决方案
推荐阅读
- html - 以全宽显示元素的内容而不重叠以下元素
- javascript - 数据表不响应提供的 json 结果来自 api 调用以用数据填充表
- python - ValueError: y 应该是一维数组,得到一个形状为 (1, 375) 的数组
- amazon-ec2 - EC2和ECS使用同一个安全组通信时发生超时错误
- c++ - 当我使用独立 COM 时,如何修复编译器错误“无效的命令行使用”
- c# - Excel VSTO 无法将按钮添加到工作表
- typescript - 键入 N 个数字的元组,后跟单个字符串
- java - Java二叉树:递归相关问题
- java - Mockito,我在控制器中测试 Post 方法做错了什么?
- google-sheets - 谷歌表格中基于日期的颜色代码交替行