c - Should useless type qualifiers on return types be used, for clarity? -


Our static analysis tools complain about a "return type on a bad type of qualifier" when in our header files The prototypes are:

  const int foo ();  

We have defined it in this way because the function is making a continuous return that can never change, assuming that with the API const clearly Is in place from

I think that it is clearly similar to starting the global variable for zero, although the C standard already states that all global will be started in zero, if obvious Has not been initialized. At the end of the day, it really does not matter. (But the static analysis tool does not complain about it.)

My question is, is there any reason that there can be a problem with this? Should we ignore the errors generated by the device, or should we cool the device at a low cost and reasonable API cost? (It gives the other const four * constants that there is no problem with the device.)

It's usually better for your code to describe it as accurately as possible. You are getting this warning because in const const int foo (); Basically meaningless the API seems obvious only if you do not know what const means the keyword does not mean overload; Static is very bad, there is no reason to add more probability of confusion.

const char * means something different than Const int , which is why your tool does not complain about it There is an indicator for continuous string, which means that calling any returning function to any code should not try to modify the contents of the string (it may be in the ROM for example). In the latter case, there is no way to implement the system that you do not make a change in return int , so the qualifier is meaningless. There will be a parallel to the return types:

  const int foo (); Char * const foo2 ();  

That will give a reason to warn your static analysis - adding a convertifier to the return value is a meaningless operation. It only makes sense when you have an FA reference parameter (or return type), like your const char * example.

In fact, I created a little test program, and the GCC has even explicitly warned about this problem:

  test.c: 6 : WARNING: The type qualifiers on the function return type have been ignored  

So this is not just your static analysis. Program which is complaining.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -