我正在尝试学习C,很有趣。
我正在使用Linux发行版。
我正在尝试编译使用kbhit()
的程序。
我用TurboC(http://www.sandroid.org/TurboC/#Download)找到了解决方法。
我按照指示进行了操作,但是make
给了我:
gettext.c: Dans la fonction « gettextTurboC »:
gettext.c:93:13: warning: les cibles pointées dans l'affectation de « int8_t * » {alias « signed char * »} vers « uint8_t * » {alias « unsigned char * »} diffèrent dans la plage signée [-Wpointer-sign]
TurboData = (int8_t *) dest;
^
In file included from TurboC.h:60,
from conio.h:49,
from gettext.c:42:
TurboC.h:250:14: error: expected « ) » before « int32_t »
#define long int32_t
^~~~~~~
/usr/include/curses.h:1238:66: note: dans l'expansion de la macro « long »
#define PAIR_NUMBER(a) (NCURSES_CAST(int,((NCURSES_CAST(unsigned long,(a)) & A_COLOR) >> NCURSES_ATTR_SHIFT)))
^~~~
gettext.c:124:10: note: pour correspondre à ce « ( »
Color = PAIR_NUMBER (ch & A_COLOR);
^~~~~~~~~~~
gettext.c:125:23: warning: les cibles pointées dans le passage de l'argument 2 de « pair_content » diffèrent dans la plage signée [-Wpointer-sign]
pair_content (Color, &dFore, &dBack);
^~~~~~
In file included from TurboC.h:60,
from conio.h:49,
from gettext.c:42:
/usr/include/curses.h:746:28: note: « short int * » attendu mais l'argument est de type « uint16_t * » {alias « short unsigned int * »}
extern NCURSES_EXPORT(int) pair_content (NCURSES_PAIRS_T,NCURSES_COLOR_T*,NCURSES_COLOR_T*); /* implemented */
^~~~~~~~~~~~
gettext.c:125:31: warning: les cibles pointées dans le passage de l'argument 3 de « pair_content » diffèrent dans la plage signée [-Wpointer-sign]
pair_content (Color, &dFore, &dBack);
^~~~~~
In file included from TurboC.h:60,
from conio.h:49,
from gettext.c:42:
/usr/include/curses.h:746:28: note: « short int * » attendu mais l'argument est de type « uint16_t * » {alias « short unsigned int * »}
extern NCURSES_EXPORT(int) pair_content (NCURSES_PAIRS_T,NCURSES_COLOR_T*,NCURSES_COLOR_T*); /* implemented */
^~~~~~~~~~~~
make: *** [Makefile:126: gettext.o] Error 1
我真的不知道该怎么办:
TurboC.h:250:14: error: expected « ) » before « int32_t »
#define long int32_t
有人可以帮我吗?
答案 0 :(得分:5)
免责声明:我将研究本世纪研究Turbo C的有用性放在一边。
问题出在TurboC.h:250的宏定义:
#define long int32_t
这是尝试通过long
重新定义内置类型int32_t
的尝试。后者在stdint.h
中定义,由编译器供应商提供。 int32_t
的定义应最终映射到32位长的内置有符号整数类型上。鉴于在现代主流体系结构上int
是32位长,int32_t
的典型定义如下所示:
typedef int int32_t;
无论如何,int32_t
是一个typedef名称。
通过long
将int32_t
定义为宏意味着将令牌long
的所有后续出现都替换为令牌int32
。除其他后果外,这还会破坏诸如unsigned long
之类的合法结构:在宏扩展之后,该结构将呈现为unsigned int32_t
。
现在,将unsigned
与typedef名称结合使用是非法的。 C语法指定要指定整数类型,我们必须使用 typedef名称或组合关键字,例如unsigned
和long
,但不能同时使用。
GCC如何报告此错误有些令人困惑。在处理语句时,
Color = PAIR_NUMBER (ch & A_COLOR);
它扩展了类似于函数的宏PAIR_NUMBER
,该宏的定义方式是它包含令牌序列unsigned
和long
。然后将long
进一步扩展为int32_t
,这会产生令牌序列unsigned
和int32_t
。在扩展的地方,编译器不希望在unsigned
之后输入typedef名称,因为语法禁止这样做。
然后假定令牌的这种无效组合是某处缺少右括号的结果。在这种情况下,这种推定是错误的,并导致令人困惑的错误消息。
答案 1 :(得分:2)
您尝试使用的“ TurboC”项目可能仅在作者计算机的特定gcc版本上的简单程序中有效。错误消息提示主要的不可修复的问题。我建议不要尝试使用它。
相反,您可以通过其他方式学习C,而无需尝试构建Turbo C源代码。如果您正在寻找类似的东西,则可以搜索ncurses
示例程序或教程。
一旦您学习了更好的语言,您也许可以返回到现在正在查看的原始源代码,并将其直接移植到ncurses。
答案 2 :(得分:1)
我正在尝试学习C,很有趣。我正在使用Linux发行版。
Linux发行版是学习C的绝佳选择。请注意,它由free software组成,您可以学习其源代码。通过研究用C编写的小型免费软件程序的源代码,您将学到很多东西(例如,来自coreutils的源代码,或者像shell的简单sash的源代码)等)。
如果您想学习C编程,请首先使用standard streams(一个直接处理键盘的程序很复杂,不适用于新手)从简单的命令行程序开始,并限制自己仅使用{{3 }}。
(您问题中的代码不在标准C中-因为它使用了一些外部库-;我不建议一开始尝试这样做)
稍后,当您更熟悉C standard library时,可以使用一些外部C programming language。 Linux发行版中有很多。您可能需要为其安装开发libraries,例如libncurses-dev
在ncurses
的Debian或Ubuntu上。
C中一个非常重要的概念是packages。详细了解它,避免它,成为它的undefined behavior。
我正在尝试编译使用kbhit()的程序
请注意,kbhit
和<conio.h>
不在C11标准中(请参阅scared ...),并且它们不在{{3 }},所以不要使用它们(在Linux或POSIX上您将找不到任何直接等效的对象)。
在Linux上,您可能要使用n1570。当然,您需要花几天时间来学习它并研究其文档。您将找不到与kbhit
等效的 direct 。阅读C standard library。
您可能要使用一些非标准库(Linux有很多非标准库)。然后阅读ncurses。
终端(以及NCURSES programming howto和Program Library HowTo)是一件复杂的事情。阅读terminal emulators,line discipline,The TTY demystified。您真的想使用诸如ncurses
(或termios(3))之类的库。
pty(7)不是编译器,而是readline
。请参阅geany对相关问题的答案。
您可能想使用一些source code editor工具,例如GNU this。它将为您运行build automation。因此,请阅读make
。
一旦您总体上熟悉C编程,您可能想了解有关Linux编程的更多信息,因此请阅读gcc
compiler。
PS。 How to invoke GCC是一个古老的C编译器(不符合标准),您甚至应该忘记。在Linux上不存在。 GCC是一个良好的,符合标准的C编译器。您应该将其与所有警告和调试信息一起使用,即在Linux上将yoursourcecode.c
编译为gcc -Wall -Wextra -g yoursourcecode.c -o yourbinary
。另请参阅ALP。 TurboC工具对于调试How to debug small programs也非常有用(在Linux上可用)。
在StackOverflow上提问时,请确保将valgrind设置为英语。我们不应该用法语解密编译器诊断程序。