ubuntu下的c语言的第一天

今天开始讲C语言了,第一天讲了c程序怎样从.c文件到.out文件运行的。讲了linux下的gcc指令。

C语言文件从编写完成到编译链接及最后生成执行文件的全过程。

source code :源代码;

header files:头文件;

proprecessing\proprecessed:预处理;

assembly:集合;

object files:目标文件;

static library:静态库;

linking:链接;

executable:可执行文件。

************************************************************************************************************************

cpp(预处理):把.h放在.c文件里生成.i文件

Static Library :运行时环境。

Hello.c   c语言文件。

Stdio.h   头文件。

Hello.i   : stdio.h放到hello.c文件后生成的文件。

Hello.s   :汇编文件。

Hello.o   :  机器语言文件。

./  执行当前路径下的.out

 

.c --------》编译器------- .s------》汇编器------.o

 

gcc filename.c -o filename

直接变成机器语言。

 

#include<stdio.h>不是c语句,预处理命令

 

gcc  -E  filename.c  –o  filename.i 

预处理命令(cpp)

gcc  –S filename.i    -o  filename.s

编译,生成汇编文件。

gcc  -C filename.s   -o  filename.o

汇编,生成机器语言文件。

echo  $?  

查看返回值。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Ubuntu下,使用C语言的pthread_create函数来创建线程。pthread_create的函数原型如下: ```c int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg); ``` 其中,thread是一个指向pthread_t类型的指针,用于存储新线程的标识符; attr是一个指向pthread_attr_t类型的指针,用于设置线程的属性(通常为NULL,表示使用默认属性); start_routine是指向函数的指针,该函数将作为新线程的起始点; arg是一个指向void类型的指针,用于向start_routine函数传递参数; 函数的返回值为0表示成功创建线程,其他值表示错误。 下面是一个例子,演示了如何在Ubuntu下使用pthread_create函数创建线程: ```c #include <stdio.h> #include <pthread.h> void *thread_func(void *arg) { int thread_id = *(int *)arg; printf("Hello from thread %d\n", thread_id); pthread_exit(NULL); } int main() { pthread_t thread; int thread_id = 1; pthread_create(&thread, NULL, thread_func, (void *)&thread_id); pthread_join(thread, NULL); return 0; } ``` 这个例子中,定义了一个名为thread_func的函数作为新线程的起始点。在主函数中,调用pthread_create函数来创建一个新线程,并将thread_func函数作为参数传递给pthread_create函数。在thread_func函数中,打印出线程的ID,并使用pthread_exit函数来终止线程。最后,使用pthread_join函数来等待新线程完成。 请注意,上述代码只是一个示例,你可以根据自己的需求对线程进行定制和调整。<span class="em">1</span><span class="em">2</span><span class="em">3</span><span class="em">4</span>

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值