about rule20.5

6.20 Standard Libraries

Moderators: misra-c, david ward

Post Reply
raghaw_k
Posts: 2
Joined: Fri May 14, 2010 11:12 am
Company: Tata Consultancy Services

about rule20.5

Post by raghaw_k » Tue May 25, 2010 1:18 pm

According to the rule 20.5, error indiaction facility should not be used even if it is well defined.
1)Is it mean that we should not declare the identifier(function and variable) with the name "errno"?
2)As per the standard library for linux "errno" MACRO is defined to function pointer call and for Visual C++ it is extern variable declaration. So does usage of "errno"(i.e. function call) on linux also violates the rule 20.5?

Lundin
Posts: 70
Joined: Mon Dec 10, 2007 1:57 pm

Re: about rule20.5

Post by Lundin » Wed May 26, 2010 2:20 pm

According to the rule "errno" shouldnt be used at all, because it -isn't- well defined. It is only relevant how it is defined in ISO C, not in some homemade C standard for this or that OS.

Pundlik Oulkar
Posts: 3
Joined: Thu Nov 20, 2008 5:11 am
Company: TCS
Location: Pune ,India

Re: about rule20.5

Post by Pundlik Oulkar » Thu May 27, 2010 5:38 am

void foo()
{
int errno;
errno = GetValue();
if(errno == 0) //Is this usage of errno violates the rule 20.5, errno is user defined variable not from the errno.h
{

}
}
int GetValue()
{
return 10;
}
Pundlik Oulkar

MMouse
Posts: 18
Joined: Thu Jul 05, 2007 12:20 am
Company: Disney
Location: Florida
Contact:

Re: about rule20.5

Post by MMouse » Thu May 27, 2010 12:04 pm

[quote="Lundin"]According to the rule "errno" shouldnt be used at all, because it -isn't- well defined. It is only relevant how it is defined in ISO C, not in some homemade C standard for this or that OS.[/quote]

I agree. Linux is written using GCC which has it's own standard. It is not ISO -C more to the point there are no defined error numbers in ISO-C. Everything says there "may" be an error number. No specification to what the error number is. BTW I once, well over a decade ago, had an error routine that checked for any return >0. Trouble was one (and only one) funnction in the library used negative numbers for errors...

I have never found any consistancy between any compiler libraries on errno. The only consistancy is those compilers who share the same library. Whilst this will usually work for for commercial compilers wherey they tend to use the same library across all their compilers for GCC the inverse is true as there are very many different libraries available. So no two people using, for example, a GCC-ARM compiler may be using the same library. Thus the errno might/will be different or missing all together.

Lundin
Posts: 70
Joined: Mon Dec 10, 2007 1:57 pm

Re: about rule20.5

Post by Lundin » Fri May 28, 2010 3:42 pm

Why would you use Linux & GCC on a safety-critical application anyhow... It will be an incredible painful and time-consuming process to ensure that the tool lives up to MISRA, let alone Linux itself. For example, MISRA mentiones that the maker of the tool should have a quality system, validation activities etc etc. How you can say that a semi-hobbyist open-source compiler lives up to that, I have no idea.

William Forbes
Posts: 29
Joined: Wed Dec 17, 2008 9:48 pm
Company: TRW Automotive

Re: about rule20.5

Post by William Forbes » Sun May 30, 2010 7:17 pm

Lundin wrote:How you can say that a semi-hobbyist open-source compiler lives up to that, I have no idea.
This is a bit unfair. The GCC compiler is probably the most widely tested piece of software ever written.
It also forms the core of some very expensive commercial compilers used in safety critical software.

Bill Forbes

MMouse
Posts: 18
Joined: Thu Jul 05, 2007 12:20 am
Company: Disney
Location: Florida
Contact:

Re: about rule20.5

Post by MMouse » Sun May 30, 2010 7:49 pm

[quote="William Forbes"][quote="Lundin"]How you can say that a semi-hobbyist open-source compiler lives up to that, I have no idea.[/quote]
This is a bit unfair. The GCC compiler is probably the most widely tested piece of software ever written.
It also forms the core of some very expensive commercial compilers used in safety critical software.

Bill Forbes[/quote]

I don't see how you can say that.... GCC is very widely used BUT most are as individual as people. GCC is the GNU Compiler Colection. It is a generic compiler but there are many versions maintained by many different people for many different targets. The code in the compilers comes from many different (uncontrolled) sources of varying standards. Most people download and build their own in uncontrolled "processes" and build and use it with any number of different libraries..... It is like doing an IQ test on one person and extrapolating it out to the whole human race.

There is no GCC test suite as such either. I know some one who looked at the suposed test suite ad said it is an unstructured incomplete partial regressiont test suite or poor quality with no provenance.... I understand that a couple of people have put one or two of the GCC compilers though the Pum-Hall and Perenial test suites with poor results.... though to be fair they are ISO C test suites not GCC test suites.

So many thousands of [different] GCC compilers have been tested to some extent with some test suites of varying quality.

Which compilers used in safety critical work does it form the core for?

misra-c
Posts: 566
Joined: Thu Jan 05, 2006 1:11 pm

Re: about rule20.5

Post by misra-c » Mon May 31, 2010 9:31 am

(1) "errno", like many other identifiers used in the standard headers, is reserved so you should NOT attempt to use it for your own purposes. You could use something like error_number instead.

(2) The standard permits errno to be implemented as a macro or as an identifier declared with external linkage. It is a violation of rule 20.5 to use errno, regardless of its implementation.

As pointed out by previous correspondents errno has a lot of implementation defined behaviour associated with it in ISO C.
---
Posted by and on behalf of
the MISRA C Working Group

Lundin
Posts: 70
Joined: Mon Dec 10, 2007 1:57 pm

Re: about rule20.5

Post by Lundin » Fri Jun 11, 2010 10:56 am

William Forbes wrote:
Lundin wrote:How you can say that a semi-hobbyist open-source compiler lives up to that, I have no idea.
This is a bit unfair. The GCC compiler is probably the most widely tested piece of software ever written.
It also forms the core of some very expensive commercial compilers used in safety critical software.

Bill Forbes
Yes it is very well-tested. Yet it doesn't conform to ISO C 9899:1990 as enforced by MISRA. It implements some hybrid between C90 and C99, best referred to as "GCC C". Thus it is a hobbyist project of creating a new language, and not relevant for C90 applications.

Post Reply

Return to “6.20 Standard Libraries”