当前gcc编程源码只能使用ascii码,如果有了非ascii码就会出现错误提示,下面将修改gcc源码,以让它支持utf-8编码编程。以下提供gcc-6.4.0-zn.tar.gz源码包,下载后root身份支持make make install,其中gcc是6.4.0,编程时使用utf-8编码,标点用半角符号,操作平台是Deepin。

下载链接

地址:https://pan.baidu.com/s/1AbjPYOPM2StNcQ9FM5clmg

密码:o7i8

第一个程序(全部ascii码)

sgf@sgf-PC:~/Documents/文档$ cat chengxu1.c

#include

#define STR "hello world!"

int main()

{

printf("%s\n",STR);

return 0;

}

sgf@sgf-PC:~/Documents/文档$ gcc -o chengxu1 chengxu1.c

sgf@sgf-PC:~/Documents/文档$ ./chengxu1

hello world!

sgf@sgf-PC:~/Documents/文档$

第二个程序(用了中文命名宏)

sgf@sgf-PC:~/Documents/文档$ cat chengxu2.c

#include

#define 字串宏 "hello world!"

int main()

{

printf("%s\n",字串宏);

return 0;

}

sgf@sgf-PC:~/Documents/文档$ gcc -o chengxu2 chengxu2.c

sgf@sgf-PC:~/Documents/文档$ ./chengxu2

hello world!

sgf@sgf-PC:~/Documents/文档$

第三个程序(用了中文命名宏,中文命名函数名)

sgf@sgf-PC:~/Documents/文档$ cat chengxu3.c

#include

#define 字串宏 "hello world!"

int 打印函数()

{

printf("母语编程好处多!\n");

return 0;

}

int main()

{

打印函数();

printf("%s\n",字串宏);

return 0;

}

sgf@sgf-PC:~/Documents/文档$ gcc -o chengxu3 chengxu3.c

sgf@sgf-PC:~/Documents/文档$ ./chengxu3

母语编程好处多!

hello world!

sgf@sgf-PC:~/Documents/文档$

第四个程序(用了中文命名宏,中文命名函数名,用typedef定义中文别名)

sgf@sgf-PC:~/Documents/文档$ cat chengxu4.c

#include

typedef float 浮点型;

浮点型 长方体体积函数(浮点型 长,浮点型 宽,浮点型 高){return(长*宽*高);}

int main()

{

浮点型 长;

浮点型 宽;

浮点型 高;

浮点型 长方形体积;

长=3;

宽=4;

高=5.5;

长方形体积=长方体体积函数(长,宽,高);

printf("长%f,宽%f,高%f,长方形体积%f\n",长,宽,高,长方形体积);

return 0;

}

sgf@sgf-PC:~/Documents/文档$ gcc -o chengxu4 chengxu4.c

sgf@sgf-PC:~/Documents/文档$ ./chengxu4

长3.000000,宽4.000000,高5.500000,长方形体积66.000000

sgf@sgf-PC:~/Documents/文档$

相关截图

de7440687469196003529e122d660659.png

77368f9d28692b385f00cf7330996011.png

7699b770af1523a000f0ff89a3d4ac35.png

说明

对于已有的库函数,第一种方法重新写一个用中文命名的相同功能的库函数,第二种方法写一个中文命名的函数调用已有的库函数,第三种方法定义一个中文命名的函数指针指向已有的库函数。

相关主题

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐