Go homepage(回首页)
Upload pictures (上传图片)
Write articles (发文字帖)

The author:(作者)delv
published in(发表于) 2014/1/8 7:47:45
It turns out, Linux is always Number 1

Turns out, Linux Number 1-Linux,Linux always order programming-IT news Turns out, Linux was always Number 1

Hi, I'm writing a simple program, I want to let this program prints out a whole number.



#include


int main() {


int linux = 701;


printf("%d", linux);


return 0;


}


Simple enough. : Really?


I put it into the code.c


I now compile and run it:


$ gcc code.c && ./a.out


Bad! Compile failed, and receive the following error message:


code.c: In function'main':


code.c:4:6: error: expected identifier or'('before numeric constant


int linux = 701;


^


Confusing!!


After Googling this error information – this is the error code needs to be preprocessed.


So, I bring the-e argument at compile time, it can compile stops after preprocessing:


$ gcc -E code.c


Preprocessed main () function code appears as follows:


int main() {


int 1 = 701;


printf("%d\n", 1);


return 0;


}


I passed out! C-language editor of preprocessing Linux changed the variable the integer 1. When the compiler encounters an int 1=701; statement, throws an error.


Now, I'm no Linux assign any values to variables:


#include


int main() {


printf("%d\n", linux);


return 0;


}


To compile and run:


$ gcc code.c && ./a.out


It compiles successfully and the output:


1


Turns out, Linux is Number1



(

事实证明,Linux总是Number 1 - Linux,Linux命令,编程 - IT资讯
事实证明,Linux总是Number 1

嗨,我正在写一个简单的程序,我要让这个程序打印出一个整数。



#include


int main() {


int linux = 701;


printf("%d", linux);


return 0;


}


够简单吧。真的吗?


我把它存成了code.c


现在我编译并运行它:


$ gcc code.c && ./a.out


糟糕!,编译失败,出现了下面的错误信息:


code.c: In function‘main’:


code.c:4:6: error: expected identifier or‘(’before numeric constant


int linux = 701;


^


困惑!!


在谷歌上搜索这个错误——得到的信息是这种错误需要对代码进行预处理。


于是,我在编译时带上了-E参数,它能让编译在预处理后停止:


$ gcc -E code.c


预处理过的main()函数代码显示如下:


int main() {


int 1 = 701;


printf("%d\n", 1);


return 0;


}


我晕!C语言的预处理编辑器竟然将变量linux换成了整数1。当编译器遇到了int 1 = 701;语句时,抛出了错误。


现在,我不对变量linux赋任何值:


#include


int main() {


printf("%d\n", linux);


return 0;


}


编译并运行:


$ gcc code.c && ./a.out


编译成功并且输出:


1


事实证明,linux总是Number1


)


If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)





QQ:154298438
QQ:417480759