找回密码
 注册
查看: 706|回复: 6

正常编译,运行问题

[复制链接]
发表于 2005-12-18 21:19:42 | 显示全部楼层 |阅读模式
我正常编译了一个测试程序,出现下面的运行情况,好象结果也没有错,开始我有些测试文件写入的代码,类似下面的报fopen等函数的问题,帮忙看下,代码在下面
4609: symbol=printf; lookup in file=./a.out [0]
4609: symbol=printf; lookup in file=/lib/tls/libc.so.6 [0]
lookup 0x08048000 0x00000194 -> 0xb7e9e000 0x00041668 /1 printf
12544
代码就是比较简单的标准C函数啊

#include "stdio.h"


typedef struct mem_struct{
void *z;
unsigned char flag;
unsigned char state;

} mem;
int main()
{
char *zz = "11";
mem *bb;
bb->z = zz;
int b= zz[0]+zz[1]*255;
printf("%d",b);

}

是magiclinux 2.0rc1
不确定是否以前有装过影响GCC的东西了
发表于 2005-12-19 09:28:27 | 显示全部楼层
glibc的调试信息?
回复

使用道具 举报

 楼主| 发表于 2005-12-19 16:36:29 | 显示全部楼层
不好意思啊,接触不久,用glibc 调试当关键词查了一下,没找到原因,不知道是不是调试信息
我编译没有加任务命令

#include "stdio.h"
#include <malloc.h>


typedef struct mem_struct{
    void *z;
    unsigned char flag;
    unsigned char state;

} mem;
int main()
{
unsigned int cc[3];
unsigned int aa = 131071;
unsigned int *l,*h;
l = malloc(sizeof(int)*3);
l[0] = 13;
l[1] = 43;
l[2] = 54;
h = l;
int b;
b = aa>>16;
printf("%d",h);

}


这段代码又没有任何信息了~

然后我加了分配内存的代码到开始的那段代码

#include "stdio.h"
#include <malloc.h>

typedef struct mem_struct{
void *z;
unsigned char flag;
unsigned char state;

} mem;
int main()
{
char *zz;
zz = malloc(sizeof(char)*3);
zz[0] = '1';
zz[1] = '1';
zz[2] = '\0';
mem *bb;
bb->z = zz;
int b= zz[0]+zz[1]*255;
printf("%d",b);

}

显示信息为以下
      5444:     symbol=printf;  lookup in file=./a.out [0]
      5444:     symbol=printf;  lookup in file=/lib/tls/libc.so.6 [0]
少了一句话

个人感觉哈,是不是他先在我编译的执行文件里找printf这个函数,没有又在/lib/tls/libc.so.6找哦,结果也没有,在内存 0x08048000 0x00000194中找到哦
回复

使用道具 举报

 楼主| 发表于 2005-12-20 13:04:12 | 显示全部楼层
麻烦会的帮邦忙啊
回复

使用道具 举报

发表于 2005-12-20 14:38:47 | 显示全部楼层
调试信息而已,不用理会它吧。
还有bb没分配内存。
回复

使用道具 举报

发表于 2005-12-20 14:44:43 | 显示全部楼层
mem *bb;
bb->z = zz;

中间加一句:
bb = malloc(sizeof(mem));
最后别忘了free
回复

使用道具 举报

 楼主| 发表于 2005-12-20 15:09:45 | 显示全部楼层
谢谢了,我也刚知道了,确实写C还不行啊,写PHP都不用管内存什么的。我也才看一个外国的帖子知道了

应该是在结定义的时候,破坏了程序的一些关于查找函数的内存导致的,所以程序就到处查找这些函数,找到后运行,所以结果没什么错,
我加了句给解构体分配内存的代码后就没有上面的情况了~~

看来C语言没到家啊
别人也有这个问题,看这个解决了
Maybe I'm missing it, but I see nowhere that you are allocating memory for msg. Usually you will get a segfault from code like this, but perhaps it is overwriting some other memory space and inadvertently turning on the debug messages?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2025-2-7 14:55 , Processed in 0.024658 second(s), 15 queries .

© 2001-2025 Discuz! Team. Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表