-
Notifications
You must be signed in to change notification settings - Fork 0
Common Questions
Description: Wiki compiling all questions lost on Teams to avoid repetitions in TA sessions (feel free to contribute)
Example:
Q Some question
A Some answer
Q Will we need to support initialiser lists such as int x[] = {0,1};
to declare an int array with 2 members
A You will need commas when initialising arrays. You can also assume that the length of the array will always be given in the square brackets
Q Will we be tested on the extern
and static
keywords? What about global variables?
A Global variables could be tested, extern
and static
will not be tested. Global variables could be initialised in the global scope
Q What's up with casting?
A Both implicit and explicit casting are not tested
Q Are chars
signed
or unsigned
by default? Will we be tested on unsigned char
and signed char
?
A The char
keyword by itself is implementation specific. You won't have to do any comparative operations on the chars though. unsigned char
and signed char
will not be tested.
Q Do we have to implement function pointers?
A No, function pointers will not be tested.
Q Do we need to implement the ternary operator (cond ? A : B)?
A Yes you could be tested on it.
Q Do I need to use an IR / how do I implement one?
A An IR is useful when you have multiple backends or frontends to avoid writing different AST generations or traversals. For example, if you are compiling from C to MIPS and X86, you can create an IR from your C AST and then traverse your IR in a "interpreter" fashion to create your assembly (where each node is primitive enough and has a generateMIPS() and a generateX86() function).
Q Do I need to optimise my compiler in any way, as for example optimising register allocation or optimising my AST?
A No, the compiler will only be marked on correctness.
Q How do I know if a decimal number is a float or a double?
A Decimal numbers are all doubles
by default. To indicate that a number is a float
it will have a postfix f
or F
. As for example float f = 1.0f;
. Floats will never have a decimal number without the f
assigned to it as that will be considered as implicit casting (see above).
Q I am getting a .cprestore
warning. Do I need to worry about it?
A No, it is most likely because you are using JAL
to jump. It is only a warning, but if you want to get rid of it you can try using JALR
instead.