当前位置:首页 > 代码 > 正文

linuxc源代码(linuxc++开发)

admin 发布:2022-12-19 15:54 95


本篇文章给大家谈谈linuxc源代码,以及linuxc++开发对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

使用GNU/gdb调试Linux C/C++可执行程序查看出错源代码、设置断点

gdb是GNU开源组织发布的一个强大的Linux程序调试工具,比图形化的调试工具更强大,主要来调试C/C++语言程序。

Debug 版本的可执行程序包含调试信息,用于程序员调试程序。

Release 版本的可执行程序往往是进行了各种优化,使得程序在代码大小和运行速度上都是最优的,以方便用户使用。

用gcc/g++编译时,要加上-g选项生成debug版本的可执行程序,否则就无法使用gdb调试了。

r 表示开始run, 如果在运行的过程中发生了错误,比如segmentation fault,可以查看此时的出错源代码:

通过b或者break设置断点,断点的设置可以通过函数名、行号、文件名+函数名、文件名+行号以及偏移量、地址等进行设置。

比如在function Peer_auto_save上设置断点,在peer.c的第136行设置断点:

从断点处继续运行

退出gdb

需要一个 linux 下c语言 的程序 300行源代码左右?谢谢

300行有点多,一般超过100行就要分模块了。你看这个行不?

#include stdio.h

#include stdlib.h

#include ctype.h

#include string.h

#define EMAX 101

char operator[]="()+-*/^";

char expr[EMAX];

struct stack_head {

struct stack_head *pre;

};

struct opt_stack_node {

struct stack_head stack;

char c;

} *opt_topp = NULL;/*The top of the operator stack*/

struct val_stack_node {

struct stack_head stack;

long long val;

} *val_topp = NULL;/*The top of the value stack*/

void stack_push(void *toppp, void *newp);

void *stack_pop(void *toppp);

void opt_stack_push(char c);

char opt_stack_pop();

void val_stack_push(long long val);

long long val_stack_pop();

int isopt(char c);/*Check if character is a operator*/

/*The set of actions in each state with a given character*/

void action_0(int i);

void action_1(int i);

void action_2(int i);

void action_3(int i);

void action_4(int i);

void action_5(int i);

void action_6(int i);

void action_7(int i);

void action_8();

void input_expr();/*To input an expression*/

void stack_push(void *toppp, void *newp)

{

struct stack_head *temp = (struct stack_head *)newp;

temp-pre = *(struct stack_head **)toppp;

*(struct stack_head **)toppp = (struct stack_head *)newp;

}

void * stack_pop(void *toppp)

{

struct stack_head *temp;

if (*(struct stack_head **)toppp == NULL) {

printf("Linked stack is empty!\n");

exit(1);

}

temp = *(struct stack_head **)toppp;

*(struct stack_head **)toppp = temp-pre;

return (void *)temp;

}

void stack_clear(void *toppp)

{

struct stack_head *temp;

while (*(struct stack_head **)toppp!=NULL) {

temp = (*(struct stack_head **)toppp)-pre;

free(*(struct stack_head **)toppp);

*(struct stack_head **)toppp = temp;

}

}

void opt_stack_push(char c)

{

struct opt_stack_node *opt_nodep

= (struct opt_stack_node *)malloc(sizeof(struct opt_stack_node));

opt_nodep-c = c;

stack_push(opt_topp, opt_nodep);

}

char opt_stack_pop()

{

struct opt_stack_node *temp

= (struct opt_stack_node *)stack_pop(opt_topp);

char c = temp-c;

free(temp);

return c;

}

void val_stack_push(long long val)

{

struct val_stack_node *val_nodep

= (struct val_stack_node *)malloc(sizeof(struct val_stack_node));

val_nodep-val = val;

stack_push(val_topp, val_nodep);

}

long long val_stack_pop()

{

struct val_stack_node *temp

= (struct val_stack_node *)stack_pop(val_topp);

long long val = temp-val;

free(temp);

return val;

}

int isopt(char c)

{

if (strchr(operator,c) == NULL || c == '\0') {

return 0;

} else {

return 1;

}

}

int compute(long long i, char opt, long long j, long long *result)

{

long long prod = 1;

switch (opt) {

case '+':

*result = i + j;

return 0;

case '-':

*result = i - j;

return 0;

case '*':

*result = i * j;

return 0;

case '/':

if (j == 0) {

printf(": Semantic Error: A divisor cannot be 0\n");

return 101;

} else {

*result = i / j;

return 0;

}

case '^':

if (j = 0) {

while (j 0) {

prod = prod * i;

j--;

}

*result = prod;

return 0;

} else if (i == 0) {

printf(": Semantic Error: "

"The power of 0 cannot be negative\n");

return 102;

} else {

while (j 0) {

prod = prod / i;

j--;

}

*result = prod;

return 0;

}

default:

return 201;

}

}

void action_0(int i)

{

char c = expr[i];

if (isspace(c)) {

action_0(++i);

} else if (isdigit(c)) {

action_1(i);

} else if (isopt(c) || c == '\0') {

switch (c) {

case '(':

opt_stack_push(c);

action_0(++i);

break;

case '-':

opt_stack_push('_');

action_1(++i);

break;

default:

printf(": Syntax Error:201\n");

}

} else {

printf(": Lexical Error:101 Unexpected character in input\n");

}

}

void action_1(int i)

{

char c = expr[i];

if (isdigit(c)) {

val_stack_push((long long)c - 48);

action_2(++i);

} else if (isopt(c) || c == '\0' || isspace(c)) {

switch (c) {

case '(':

opt_stack_push(c);

action_0(++i);

break;

case '-':

opt_stack_push('_');

action_1(++i);

break;

default:

printf(": Syntax Error:211\n");

}

} else {

printf(": Lexical Error:111 Unexpected character in input\n");

}

}

void action_2(int i)

{

char c = expr[i];

if (isdigit(c)) {

val_stack_push((long long)c - 48 + val_stack_pop() * 10);

action_2(++i);

} else if (isopt(c) || c == '\0' || isspace(c)) {

action_3(i);

} else {

printf(": Lexical Error:121 Unexpected character in input\n");

}

}

void action_3(int i)

{

char c = expr[i];

if (isspace(c)) {

action_3(++i);

} else if (isopt(c) || c == '\0' || isdigit(c)) {

switch (c) {

case '^':

action_4(i);

break;

case '*':

case '/':

action_5(i);

break;

case '+':

case '-':

action_6(i);

break;

case ')':

action_7(i);

break;

case '\0':

action_8();

break;

default:

printf(": Syntax Error:231\n");

}

} else {

printf(": Lexical Error:131 Unexpected character in input\n");

}

}

void action_4(int i)

{

char c = expr[i];

char top_opt = opt_topp-c;

switch (top_opt) {

case '+':

case '-':

case '(':

case '$':

case '*':

case '/':

case '^':

opt_stack_push(c);

action_0(++i);

break;

case '_':

val_topp-val = -val_topp-val;

opt_stack_pop();

action_4(i);

break;

default:

printf(": Unexpected Error:341\n");

}

}

void action_5(int i)

{

char c = expr[i];

char top_opt = opt_topp-c;

long long rs;

long long left;

long long right;

switch (top_opt) {

case '+':

case '-':

case '(':

case '$':

opt_stack_push(c);

action_0(++i);

break;

case '*':

case '/':

case '^':

right = val_stack_pop();

left = val_stack_pop();

if(compute(left, opt_stack_pop(), right, rs)==0) {

val_stack_push(rs);

action_5(i);

}

break;

case '_':

val_topp-val = -val_topp-val;

opt_stack_pop();

action_5(i);

break;

default:

printf(": Unexpected Error:351\n");

}

}

void action_6(int i)

{

char c = expr[i];

char top_opt = opt_topp-c;

long long rs;

long long left;

long long right;

switch (top_opt) {

case '(':

case '$':

opt_stack_push(c);

action_0(++i);

break;

case '+':

case '-':

case '*':

case '/':

case '^':

right = val_stack_pop();

left = val_stack_pop();

if(compute(left, opt_stack_pop(), right, rs)==0) {

val_stack_push(rs);

action_6(i);

}

break;

case '_':

val_topp-val = -val_topp-val;

opt_stack_pop();

action_6(i);

break;

default:

printf(": Unexpected Error:361\n");

}

}

void action_7(int i)

{

char c = expr[i];

char top_opt = opt_topp-c;

long long rs;

long long left;

long long right;

switch (top_opt) {

case '(':

opt_stack_pop();

action_3(++i);

break;

case '$':

printf(": Syntax Error:271 Unclosed parenthesis,"

" expect another ')'\n");

break;

case '+':

case '-':

case '*':

case '/':

case '^':

right = val_stack_pop();

left = val_stack_pop();

if(compute(left, opt_stack_pop(), right, rs)==0) {

val_stack_push(rs);

action_7(i);

}

break;

case '_':

val_topp-val = -val_topp-val;

opt_stack_pop();

action_7(i);

break;

default:

printf(": Unexpected Error:371\n");

}

}

void action_8()

{

char top_opt = opt_topp-c;

long long rs;

long long left;

long long right;

switch (top_opt) {

case '(':

printf(": Syntax Error:281 Unclosed parenthesis,"

" expect another '('\n");

break;

case '$':

printf("%lld\n",val_stack_pop());

break;

case '+':

case '-':

case '*':

case '/':

case '^':

right = val_stack_pop();

left = val_stack_pop();

if(compute(left, opt_stack_pop(), right, rs) == 0) {

val_stack_push(rs);

action_8();

}

break;

case '_':

val_topp-val = -val_topp-val;

opt_stack_pop();

action_8();

break;

default:

printf(": Unexpected Error:381\n");

}

}

void input_expr()

{

scanf("%100[^\n]", expr);

while (getchar() != '\n') {}

}

int main()

{

printf("\nErGeCalculator version 1.0.2 (2012-10-15)\n"

"The maximum length of expression is 100 characters\n"

"Quit with 'q()'\n\n"

" ");

input_expr();

while (strcmp(expr,"q()") != 0) {

stack_clear(opt_topp);

stack_clear(val_topp);

opt_stack_push('$');

action_0(0);

printf(" ");

input_expr();

}

return 0;

}

在网上找到的linux下用C遍历目录的源代码 具体看补充。。

1、系统里面没有/usr/keygoe/ini文件夹或没有权限。可以修改main, 遍历命令行传入的文件夹;

2、filename设置为[256][256],如果文件比较多,程序会崩溃的;

3、遍历子文件夹时,只保存了文件名,没有添加上级路径。

linux下怎么查看c函数库的源代码

头文件在/usr/include/sys/time.h

如果要看定义,下载glibc的源代码。

linux 怎么编译c的源程序的?gcc,编译命令是什么?

编译方法:格式 gcc [option] [sourcefilename]常用的选项最简单的是:gcc hello.c默认的情况下将生成a.out的可执行性文件,

只需要在终端上输入./a.out就可以看到执行的结果,如果你想指定生成目标文件的名字那么你可以加上 -o选项,命令如下:gcc -o hello hello.c

命令:gcc -c hello hello.c

扩展资料:

gcc命令的基本用法

gcc[options] [filenames]  

其中,filenames为文件名;options为编译选项。

当不使用任何编译选项编译hello.c时,gcc将会自动编译产生一个a.out的可执行文件:

[root@localhost c]# ls  

hello.c  

[root@localhost c]# gcc hello.c  

[root@localhost c]# ls  

a.out  hello.c 

执行:

[root@localhost c]# ./a.out  

Hello, World! 

使用-o编译选择,可以为编译后的文件指定一个名字:

[root@localhost c]# ls  

a.out  hello.c  

[root@localhost c]# gcc hello.c -o hello  

[root@localhost c]# ls  

a.out  hello  hello.c  

执行:

[root@localhost c]# ./hello  

Hello, World! 

注意:使用-o选项时,-o后面必须跟一个文件名,即:-o outfile。

为了便于描述后面的选项,删除hello和a.out可执行文件。

关于linuxc源代码和linuxc++开发的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/11380.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载