小编Akh*_*hil的帖子

编译器在声明未定义类型的指针时未显示错误

我使用gcc编译器编译了以下c代码:

#include <stdio.h>

struct node{
        int info;
        struct test* next;
};

int main()
{
        struct node start;
        struct node* p;
        start.info = 2;
        start.next = (struct test*)&start;
        printf("start.next = %p \n",start.next);
        p = start.next;
        printf("p->info = %d\n",p->info);
}
Run Code Online (Sandbox Code Playgroud)

但令我惊讶的是,在声明next(in structure node)作为指向未声明类型(struct test)的指针之后,仍然编译成功!编译完上述程序后,其打印仅发出如下警告:

test.c:15:4: warning: assignment from incompatible pointer type [enabled by default]
  p = start.next;
    ^
Run Code Online (Sandbox Code Playgroud)

现在我怀疑为什么编译器没有因为没有声明而产生错误structure test

c gcc pointers declaration

1
推荐指数
1
解决办法
128
查看次数

Windows和Linux中printf的区别

实际上除了核心C语言之外,还有一个C库.如果我的理解是正确的,那么函数就像printf是C库的一部分.现在我在Windows中使用Turbo C中的C编程以及在Linux中使用gcc.

我的问题是:printf在Windows和Linux中,函数的代码实现是否相同?最终,该printf函数必须在核心操作系统中调用一个函数(在两种情况下)都会在屏幕上显示ASCII字符?因此,由于两个操作系统不同,printf在这两种情况下代码的实现是否也会有所不同?

c linux windows printf

1
推荐指数
1
解决办法
1124
查看次数

代码工作正常没有波动?

嗨我最近用以下骨架编写了一个代码:

variable;

callback(){
//variable updated here
}

thread_function(){
//variable used
}

main(){
//callback registered
//thread registered
}
Run Code Online (Sandbox Code Playgroud)

我发现无论何时variable在回调时更新,它都会在线程中自动更新,而不会将其声明variable为volatile.好吧,我不清楚它是如何管理的.先感谢您.之间,从使用代码编译的库中调用callback().

c multithreading volatile

0
推荐指数
1
解决办法
77
查看次数

标签 统计

c ×3

declaration ×1

gcc ×1

linux ×1

multithreading ×1

pointers ×1

printf ×1

volatile ×1

windows ×1