exit and gcc options

The exit command terminates a script, just as in a C program. It can also return a value, which is available to the script's parent process.

Every command returns an exit status (sometimes referred to as a return status or exit code). A successful command returns a 0, while an unsuccessful one returns a non-zero value that usually can be interpreted as an error code. Well-behaved UNIX commands, programs, and utilities return a 0 exit code upon successful completion, though there are some exceptions.

Likewise, functions within a script and the script itself return an exit status. The last command executed in the function or script determines the exit status. Within a script, an exit nnn command may be used to deliver an nnn exit status to the shell (nnn must be an integer in the 0 - 255 range).

---------------------------------------------------------

But sometimes it is necessary to get an assembly code listing of ones program. This is desirable if we need to say, get an idea of the values stored in the registers. This is also possible in gcc using the -S switch.

$ gcc test.c -S -g


The above command will create a text file called test.s which contains the assembly code of our program. The -g flag is optionally used to produce debug symbols and line number information.

You can optimize the compiler using the -O flag followed immediately by a number (between 0 and 3) which states the level of optimization. It is good to optimize ones programs as it results in faster binaries.

$ gcc -O2 -o test test.c


It is worth noting that one can turn off the optimization by using the -O0 switch.
-------------------------------------------------------

Common gcc options:

cc -E :preprocessor
cc -S :create or show assembly coding
cc -o bject filename
cc -g :debug info
cc -O ptimized code
cc -O2 ptimized code with optimization level increased
cc -Wall :create or show all warning
cc -D_SYMBOL_ : Symbol for prerpcessor

You can use gcc instead of cc.
---------------------------------------------------
http://blog.csdn.net/lida2003/article/details/6973469
char和unsigned char强制转换成int后的差异

猜你喜欢

转载自wwwjjq.iteye.com/blog/1553511