Disadvantages of a compiler

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Disadvantages of a compiler

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A programmer has 200 lines of code with one syntax error on line 150. What happens when they compile it?
A No executable is produced, so none of the program can be run until the error is fixed
B Lines 1 to 149 run and the compiler stops at line 150
2. Which is a disadvantage of using a compiler while developing a program?
A After every small change, the whole program must be recompiled before testing
B Only the changed line needs to be translated, which makes testing confusing
3. A student compiles a program on a Windows PC. Which statement is correct?
A The executable file will work on every type of computer without changes
B The executable file may not work on a different type of machine, such as a Mac
4. Which statement about testing part of a program with a compiler is true?
A You can run one finished section while other sections still contain errors
B You cannot test one section until the whole program compiles without errors
5. Which is a DISADVANTAGE of a compiler?
A The program must be recompiled for each different type of machine
B The executable runs without the compiler being needed

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1compile(whole_program) -> 3 errors, no executable AA compiler does not run any part of the program if there are errors. It translates the whole program first, and nothing runs until all errors are removed.
2change 1 line -> recompile everything -> run BIF errors_found THEN no_executable ELSE run
3Errors must be cleared before any part of the program will run CTesting even a small change is slow because the whole program has to be translated again before it can be tried
4An executable is machine dependent and only works on one type of machine DThe executable is machine dependent. It only works on the type of machine it was compiled for, so it must be recompiled for each different machine type.
5Line 5 is correct, so a compiler will run lines 1 to 5 and stop at the error on line 6 EThe compiler stops and produces no executable, so no part of the program can run until every error is fixed
6Compiled once on a PC, so the same executable will run on any phone, tablet or Mac Fprog_windows.exe on Mac -> fails to run

Definitions

compiler disadvantages

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
compiled ← _______(sourceCode)
2.
IF errorCount _ 0 THEN OUTPUT "Fix errors first" ENDIF
3.
IF machineType = targetType THEN run(__________) ENDIF
4.
edit(line5) _______(program) run(program)
5.
IF errorCount = _ THEN run(executable) ENDIF

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A edit one line of the code
B compile the whole program
C wait for translation to end
D run the old executable
Question 2
A compile game.c
B error found on line 12
C partial executable is made
Question 3
A compile one line at a time
B fix every error reported
C run the executable
Question 4
A built on a Windows PC
B exe is machine independent
C it will not run on a Mac
Question 5
A change one number in code
B recompile the whole program
C testing small changes is fast

Answer Key

Disadvantages of a compiler
Section A: Quick Questions
Q1
A — No executable is produced, so none of the program can be run until the error is fixed
Q2
A — After every small change, the whole program must be recompiled before testing
Q3
B — The executable file may not work on a different type of machine, such as a Mac
Q4
B — You cannot test one section until the whole program compiles without errors
Q5
A — The program must be recompiled for each different type of machine
Section B: Match the Pairs
Q1
compile(whole_program) -> 3 errors, no executable → The compiler stops and produces no executable, so no part of the program can run until every error is fixed
Q2
change 1 line -> recompile everything -> run → Testing even a small change is slow because the whole program has to be translated again before it can be tried
Q3
Errors must be cleared before any part of the program will run → IF errors_found THEN no_executable ELSE run
Q4
An executable is machine dependent and only works on one type of machine → prog_windows.exe on Mac -> fails to run
Q5
Line 5 is correct, so a compiler will run lines 1 to 5 and stop at the error on line 6 → A compiler does not run any part of the program if there are errors. It translates the whole program first, and nothing runs until all errors are removed.
Q6
Compiled once on a PC, so the same executable will run on any phone, tablet or Mac → The executable is machine dependent. It only works on the type of machine it was compiled for, so it must be recompiled for each different machine type.
Section C: Definitions
Q1
compiler disadvantages — A compiler must translate the whole program without errors before any of it runs, and its executable only works on one machine type, so testing small changes is slow.
Section D: Fill in the Blanks
Q1
compiled ← compile(sourceCode)
Q2
IF errorCount > 0 THEN OUTPUT "Fix errors first" ENDIF
Q3
IF machineType = targetType THEN run(executable) ENDIF
Q4
edit(line5) compile(program) run(program)
Q5
IF errorCount = 0 THEN run(executable) ENDIF
Section E: Spot the Error
Q1
D — The old executable does not contain the change. With a compiler the whole program must be recompiled, then the new executable is run to test the change.
Q2
C — A compiler must translate the whole program without errors. If there is an error, no executable is made and no part of the program can run.
Q3
A — A compiler translates the whole program before anything runs. Translating one line at a time is how an interpreter works.
Q4
B — A compiled executable only works on the type of machine it was compiled for, so it is machine dependent, not independent.
Q5
C — Even a tiny change means recompiling the whole program before it can be tested, so testing small changes is slow, not fast.