Re: K&R2 variable definition



Clausfor said:

Hello everybody,
I cannot find where in the K&R2 it is stated that variables must be
defined at the beginning
of a block and not within other lines.

You're looking for an explicit prohibition, but you won't find one. What you
have instead is absence of permission. See page 236, grammar for
compound-statement, which shows that declarations *may* occur at the
beginning of a compound statement. Now look for other places in the grammar
where declarations *may* occur, and look at... well, at what isn't there.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
.



Relevant Pages

  • Re: Question about "mixed declarations and code" in C89/C90
    ... The C99 grammar for a compound statement is: ... But the C99 standard does refer to "mixed declarations and code" in the ...
    (comp.lang.c.moderated)
  • Re: [Long, historical] Re: Var* b or Var *b
    ... I suggest that all declarations in this style come ... Another idea is a compiler warning, ... > language's grammar. ... is just inconsistent with the second definition above and the spirit ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Current coding standard documentation
    ... you come to this example from the syntax defn you give. ... statement is, well, _part_ of the compound statement. ... think about a language grammar for it's rules to make sense. ... The languge grammar defines its rules. ...
    (borland.public.delphi.non-technical)
  • Re: Order of execution question
    ... C90 does not allow declarations and initialisation of variables ... No, I am very lazy. ... '}') is syntactically nothing more than a compound statement. ...
    (comp.lang.c)
  • Re: role of semicolon
    ... > Depends on which way you wish to go in the grammar. ... Now that could be viewed as a defect in the standard if you expect the ... applied to an overall function body, because as it stands they are not. ... statements within a compound statement, ...
    (comp.lang.c)