Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dir 2.1 compilation errors
In Dir 2.1 , "A conforming compiler is permitted to produce an object module despite the presence of compilation errors."
I should explain this situation for the programmers, but I do not know any real compilers, producing an object module with the presence of compilation errors.
Do anyone know a compiler which can produce an object module with the presence of compilation errors?

Dr. Ogawa Kiyoshi.
We will start by giving some more background to the use of the term "compiler error".

A conforming C implementation (C99 must produce at least one diagnostic message if there is a violation of the C syntax or a constraint is broken. However, there is no restriction on the form of the message, the number of messages or whether object code is produced . We will refer to such violations are "constraint errors".

Users tend to refer to these diagnostics as "compiler errors" and "compiler warnings", but these are not terms that are defined in the standard. A compiler may choose whether a "constraint error" produces a "compiler error" or a "compiler warning". The following example contains a "constraint error", but the gcc(v3.4) compiler produces a "compiler warning" and object code.
void foo (void)
  return 0;  // Violates constraint in C99
             // A return statement with an expression shall not appear in a function whose return type is void.

int main (void)
  return 0;
Another example of a "compiler warning" in gcc occurs when assigning an integer value to a pointer or vice versa without using a cast. This is not to say that gcc is incorrect, since a compiler is free to choose whether object code is issued in such circumstances.

Directive 2.1 refers to "compiler errors" and it is a directive rather than a rule, because we cannot define what a particular compiler will treat as an "error". You may subjectively think you know what it means, but it is impossible to define precisely. It may, for example, be a particular level of warning, or perhaps those messages preceded by the word "Error" in English or by a different word in another language.

All "constraint errors" are covered by rule 1.1 of the MISRA C:2012 guidelines, but may also violate directive 2.1. Directive 2.1 also covers other issues that a particular compiler considers are serious. These may be messages concerning undefined behaviour (e.g. index out of bounds) or a misuse of a language extension.

As we have shown in the example above, some compilers will produce object code in the presence of a "constraint error". We do not have an example of a compiler which produces object code for a "compiler error", but this is not prevented by the C standard and so must be allowed for.
Posted by and on behalf of the MISRA C Working Group

Forum Jump:

Users browsing this thread: 1 Guest(s)