龙芯俱乐部开源技术社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 6024|回复: 1

修改gcc源码使其支持utf-8编码编程

[复制链接]

9

主题

62

帖子

2848

积分

金牌会员

Rank: 6Rank: 6

积分
2848
发表于 2020-8-17 16:12:46 | 显示全部楼层 |阅读模式
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 <stdio.h>
#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 <stdio.h>
#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 <stdio.h>
#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 <stdio.h>
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编译以上程序



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x

9

主题

62

帖子

2848

积分

金牌会员

Rank: 6Rank: 6

积分
2848
 楼主| 发表于 2020-8-20 08:05:21 | 显示全部楼层
对于已有的库函数,第一种方法重新写一个用中文命名的相同功能的库函数,第二种方法写一个中文命名的函数调用已有的库函数,第三种方法定义一个中文命名的函数指针指向已有的库函数.
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|龙芯俱乐部开源技术社区

GMT+8, 2024-4-25 14:33 , Processed in 0.101620 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表