cmsc212: intro to low-level programming concepts
DESCRIPTION
CMSC212: Intro to Low-Level Programming Concepts. Section 0101: 9:00am – 9:50am Section 0102: 10:00am-10:50am Monday & Wednesdays Room 3118. Emacs Stuff. With Xming [emacs &] calls up a new window with emacs and returns access to command-line - PowerPoint PPT PresentationTRANSCRIPT
CMSC212: Intro to Low-Level Programming Concepts
Section 0101: 9:00am – 9:50amSection 0102: 10:00am-10:50amMonday & WednesdaysRoom 3118
Emacs Stuff
•With Xming▫[emacs &] calls up a new window with
emacs and returns access to command-line▫[emacs file1 &] calls up emacs with file1
read into new window▫Note: & commonly used to put process into
background [bg] to view background processes [fg %number] to pull background process
“number” to foreground
Emacs Stuff Cont’d
•Without Xming▫[emacs], [emacs file1]
•More commands▫[Ctrl-x Ctrl-c] Exit emacs▫[Ctrl-x Ctrl-s] Save file (save often)
•Useful keybinds for cursor movement▫[Ctrl-a] Beginning of current line▫[Ctrl-e] End of current line▫[Escape-<] Front of file▫[Escape->] End of file
Emacs Editing
•Keybinds for deleting text▫[Ctrl-k] Delete to end of line▫[Ctrl-u] Delete line
•Cut/pasting▫[Ctrl-space] Mark head end of cut▫[Ctrl-w] Mark tail end of cut▫[Ctrl-y] Paste
GCC Compilation and Linking
▫File test1.c
▫#include <stdio.h>int main() {
printf("This is CMSC 212.");printf(“hello world!\n");printf(“bye world!\n");return 0;
}
GCC Compilation and Linking
•Method 1▫[gcc –c test1.c]
Creates an object file test1.o▫[gcc test1.o –o test1]
Links object file(s) and outputs executable•Method 2
▫[gcc test1.c] No intermediates, produces executable a.out
▫[gcc test1.c –o test1] No intermediates, produces executable test1
Gcc Compilation and Linking Multiple files
▫File1: questionablepractices.h
▫#ifndef _QUESTIONABLE_H_#define _QUESTIONABLE_H_#include <stdio.h>
//Prototypesvoid infiniteLoop();void infiniteStack();#endif
Gcc Compilation and Linking Multiple files
▫File2: questionablecode.c
▫#include “questionablepractices.h”void infiniteLoop(){
while(1)printf(“how to terminate?\n”);
} void infiniteStack(){
printf(“o really?\n”);infiniteStack();
}
Gcc Compilation and Linking Multiple files
▫File3: questionablemain.c
▫#include “questionablepractices.h”
int main(){infiniteLoop();//infiniteStack();return 0;
}
Gcc Compilation and Linking Multiple files•How to build this?
▫gcc questionablemain.c questionablecode.c -o question Generates executable called “question”
▫gcc –c questionablemain.c questionablecode.c Generates object files questionablemain.o
questionablecode.o▫gcc questionablemain.o questionablecode.o
-question Links the two files and creates executable
Xming emacs + compilation
•Another way to compile directly through emacs▫[Escape-x] type compile
Suggests make –k (will get into later when we use make)
For now, use the standard gcc commands•Notice the new menu titled “Compile”
More Unix commands+options
•More useful commands▫[cp –r] Copy directories recursively, i.e. all
sub-file/directories▫[man cmd] pulls up the manual and
description of options for cmd, e.g. [man cp]
Chmod• [chmod [references][operator][mode] file(s)]
• reference classes• u (user/owner), g (users who are members of file
group), o (users not in g), a (all from before, i.e. ugo)• operator
• + (add modes to reference classes)• - (remove modes from reference classes)• = (specified modes are made exact for reference
classes)• Mode
• r (read), w (write), x(execute)• X, s, t (not covered)
Chmod
•E.g.•chmod ug+rw mydir
▫Gives read/write mode to user and file group of directory mydir
Questions?