【发布时间】:2018-06-11 10:00:02
【问题描述】:
在Practical C Programming的书Chapter 7 Programming Process中有一个makefile:
File: calc1/makefile.gcc
#-----------------------------------------------#
# Makefile for unix systems #
# using a GNU C compiler #
#-----------------------------------------------#
CC=gcc
CFLAGS=-g -D__USE_FIXED_PROTOTYPES__ -ansi
#
# Compiler flags:
# -g -- Enable debugging
# -Wall -- Turn on all warnings (not used since it gives away
# the bug in this program)
# -D__USE_FIXED_PROTOTYPES__
# -- Force the compiler to use the correct headers
# -ansi -- Don't use GNU extensions. Stick to ANSI C.
calc1: calc1.c
$(CC) $(CFLAGS) -o calc1 calc1.c
clean:
rm -f calc1
什么是“正确的标题”?为什么选项参数-D和__USE_FIXED_PROTOTYPES__之间没有空格?
在GCC mirror中,有:
/* __USE_FIXED_PROTOTYPES__ used to be required to get prototypes for
malloc, free, etc. on some platforms. It is unclear if we still
need it, but it can't hurt. */
#define __USE_FIXED_PROTOTYPES__
Re: Is __USE_FIXED_PROTOTYPES__ really necessary?有解释。
但我没有得到分数。
这本 PRACC 书出版于 1997 年,有点旧,但仍然非常有用。 Makefile 有点过时了,不知道是否还需要 .gcc 扩展名。
Errata for Practical C Programming 中均未提及这些。
【问题讨论】:
-
-D和__USE_FIXED_PROTOTYPES__之间的空格是可选的。请注意,从某种意义上说,-ansi标志已过时,您现在应该使用-std=c90(或多或少是-ansi的意思)或-std=c99或-std=c11(最好是后者)之一,或 GNU 变体之一(例如-std=gnu11— 这是 GCC 7(以及 6、和 5 IIRC,但在早期版本中不是默认值)中的默认值。 -
2017年用1997年的编程书,2018年的错误,就像用1307年的建筑书一样。
-
.gcc到makefile的后缀可能用于允许为不同的编译器编写不同的makefile。如果您打算使用 GCC,则确实不需要后缀。它唯一的危害是你必须输入make -f makefile.gcc而不仅仅是make——至少在你输入ln -s makefile.gcc makefile(或mv makefile.gcc makefile)之前是这样。__USE_FIXED_PROTOTYPES__的东西在 20 年前似乎是必要的;不过,在这个千年的大部分时间里,这并不是必需的。从生成文件中删除它;它是现在无关紧要的历史材料。 -
您能否明确说明您使用这本书的哪个版本?是不是第三个?