Course Information
Prof: Gordon Turpin
Email: gordon@cse.yorku.ca
-only send mail from prism account
-use a subject header "2031: …"
Hello World
#include <stdio.h>
int main(void)
{
printf("Hello World!"\n");
return 0;
}
- #include <stdio.h>
- This file is replaced in the header in compile time
- stdio.h does not contain executable code
- only definition of constants
- include statements
- and function prototypes
- 'printf'
- A function call
- (method is a function, method is a java term)
- When it encounters a function call like 'printf'
- It wants the function prototype of printf
- It wants the function prototype of printf
- A function call
- only definition of constants
- This file is replaced in the header in compile time
- int main(void)
- 'void' means it takes no parameters
- 'main' returns an 'int'
- 'void' means it takes no parameters
- return 0;
- indicates success
- unspecified types are assumed to be 'int'
- indicates success
- printf
- most basic print type
- '\n' sends a new line after the text
- most basic print type
- This program doesn't return a '0' because printing is not the same as returning
Compiling C
- Simplest way to compile
cc hello.c
ls a.out
cat hello.c
- 'cat' prints out the code for hello.c in console
- cat is called from /bin/cat
- cc is the compile command
- cc created a.out
- to create a different file name
- use cc –o hello hello.c
- 'hello' is the filename
- -o is the 'flag' to create a different name
- 'hello' is the filename
- cc –o hello –Wall hello.c
- –Wall will allow the compiler point out errors in code
- –Wall will allow the compiler point out errors in code
- cc –o hello –Wall -pedantic hello.c
- allows you to see if code will run on older versions of C
- allows you to see if code will run on older versions of C
- cc –o hello –Wall -pedantic –c hello.c
- stops compilation when the object module is produced
- Produces the file 'hello.o'
- nm hello.o
- shows the function 'main' in the T (text)
- and there is a call for a function 'printf'
- shows the function 'main' in the T (text)
- stops compilation when the object module is produced
- cc –o hello –Wall –pedantic –c -E hello.c
- stops the compilation after the preprocessor phase
- Replaces #define with code supplied for that function
- stops the compilation after the preprocessor phase
- echo $PATH
- returns the paths where the shell will look for the commands you are passing
- separated by ':'
- separated by ':'
- the last place bash looks in is the current directory
- ./a.out will find a.out within your path
- PATH=$PATH:..
- Adds ' ..' to the $PATH
- Adds ' ..' to the $PATH
- a.out only needs executable permission to run
- if you write a shell script you would need execute and read permission
chmod
- 9 permission bits
- ---------
- User
- User
- ---------
- Group
- Group
- ---------
- Owner
- Owner
- Read = 4
- Write = 2
- Execute = 1
- Non = 0
- 'chmod 751 a.out 'gives
- user
- r/w/e
- r/w/e
- group
- r/e
- r/e
- owner
- e
- e
Comments
- /*comment in here */
No comments:
Post a Comment