GATE / CS ARCHIVE

GATE CSE 2005 / QUESTION 61

Misspelled keyword that is a legal identifier

Programming in C · Functions & Parameter Passing · Full GATE CSE 2005 paper

GATE 2005, Q61 2 marks · MCQ
Report issue

Functions & Parameter Passing

Question 61, GATE 2005: Line 3 of historical C code is fro(I=0, I<N, I++); inside int main(){int I, N; ...}. During object-module creation is the response A no compilation error; B lexical error only; C syntactic error only; D both? Preserve the printed identifier fro and comma-separated expressions, not a repaired for loop.
Question 61, GATE 2005: Line 3 of historical C code is fro(I=0, I<N, I++); inside int main(){int I, N; ...}. During object-module creation is the response A no compilation error; B lexical error only; C syntactic error only; D both? Preserve the printed identifier fro and comma-separated expressions, not a repaired for loop.
Tap to enlarge
Your answer
Answer & solution

Answer: A under C90; modern C needs a diagnostic (no official key was published)

The printed line is fro(I=0, I<N, I++); with commas, not semicolons. Lexically fro is a valid identifier, and syntactically this is a function call with three arguments, not a for statement. Under the historical C90 implicit-function-declaration rule, an object module can be produced, so A is the intended compilation-stage answer; a missing definition may fail at link time. In C99 and later the undeclared function requires a diagnostic, but this is not a lexical or grammar error of the kind offered. The argument side effects also give undefined runtime behavior under C90 because I is modified more than once without an intervening sequence point; no runtime result is asserted. The paper preserve fro and commas.

The lexer accepts fro as an ordinary identifier. The grammar accepts the following parentheses as a function call whose three arguments are I=0, I<N, I++. Thus misspelling for does not by itself create a lexical or grammar error. Older C allowed an implicit function declaration; an undefined fro may be discovered later by the linker. Modern C requires a diagnostic for the undeclared function, and runtime side effects are separately problematic. The intended old compilation-stage answer must not be presented as portable modern C.

Original paper, page 7