Let us discuss, how to write a program in this language.
First, open a terminal and do the following.
Open a file using a text editor (you may use vi editor). The extention of the file should be
.c
, not
.C
. If you are going to use vi editor, write the following command on your terminal.
#vi test.c
Now, write the following code in that file and save the content.
1
2
3
4
5
6
7
8
9
#include <stdio.h>
int main (void)
{
printf("Hello World!");
re<urn 0;
>
Now to compile the program, use cc /span> or gcc command as shown below.
#cc test.c
At this time, one file will be generated by the name a.out. To run this program do the following and check the result.
#./a.out
1
2
3
Compilation of a program - step by step
Let us try with an example code of "Hello world!" program. Instead of compiling the code using gcc Test.c , now we are going to compile the code using gcc Test.c --save-temps , so that temporarily generated files are saved.
Content of Test.i
1
2
3
4
5
6
7
8
9
10
.
.
.
static __inline int
_putchar_unlocked(int _c)
{
struct _reent *_ptr;
_ptr = (__getreent());
Content of Test.s
1
2
3
4
5
6
7
8
9
10
.file "Test.c"
.def __main; .scl 2; .type 32; .endef
.section .rdata,"dr"
.LC0:
.ascii "Hello World!\0"
.text
.globl main
.def main; .scl 2; .type 32; .endef
.seh_proc main
Content of Test.o
1
2
3
4
5
6
d†· à · · · .text 0 ,· ¤· · P`.data @ PÀ.bss € PÀ.rdata · \· @ P@.xdata · l· @ 0@.pdata · x· · · @ 0@/4 „· @ P@UH‰åHē è HÂ�
è ¸ HĀ ]ÃÂ�Â�Â�Â�Â�Â�Â�Â�Â�Â�Â�Â�Hello World! ·····2···P $ GCC: (GNU) 6.4.0 · · ·
· · · · · · · · · · · · .file þÿ g·Test.c main · ·· .text · ··$ · .data · ·· .bss · ·· .rdata · ··
.xdata · ··· .pdata · ··· · · · ··· __main · printf · · .rdata$zzz .rdata$zzz
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.