All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
It turns out, Linux is always Number 1

Writer: delv Article type: IT Message (IT资讯) Time: 2014/1/8 7:47:45 Browse times: 349 Comment times: 0

It turns out, Linux is always Number 1(事实证明,Linux总是Number 1,)


Head photo

Go homepage
Upload pictures
Write articles

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

)




There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.