修改gcc源码使其支持utf-8编码编程
Tofloor
poster avatar
sigaofeng
deepin
2020-08-15 23:09
Author
本帖最后由 sigaofeng 于 2020-8-15 15:20 编辑

gcc编程源码只能使用ascii码,一旦出现非ascii则报错.修改gcc源码使其支持utf-8编码编程.修改后的源码:
链接:https://pan.baidu.com/s/1AbjPYOPM2StNcQ9FM5clmg 密码:o7i8
下载后root身份make   make install
gcc是6.4.0
编程时使用utf-8编码,标点用半角符号
第一个程序(全部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/文档$


中科智灵,Geany均可使用本版gcc编译以上程序








Reply Favorite View the author
All Replies
avatar
hww
deepin
2020-08-16 02:35
#1
点个赞!6666
Reply View the author
avatar
sigaofeng
deepin
2020-08-18 19:33
#2
对于已有的库函数,第一种方法重新写一个用中文命名的相同功能的库函数,第二种方法写一个中文命名的函数调用已有的库函数,第三种方法定义一个中文命名的函数指针指向已有的库函数.
Reply View the author