Pointer Targets In Assignment Differ In Signedness

Porting to gcc 4 (Warnings)

Overview

The transition from gcc version 3.3.4 (as used until VLT2008) to gcc 4.x caused a row of problems with inconsistencies and incompatibilities in our code, as described in TWiki page "Porting to gcc 4 (Mandatory Changes for VLT2009)". That page describes only the errors preventing from compiling successfully. In addition, a very large number of warnings occur, often obstructing the view of the serious errors. Just to give an idea: almost 50000 warnings were generated compiling the VLT Common Software, owing to the gcc change from version 3 to 4. Some of these warnings give hints about deprecated functionality which will no longer be supported in future compiler versions. Some of these warnings are in fact errors forced into warnings by specific compiler options just to get the code to pass the compiler. Many of these warnings are due to a lower tolerance level towards deviations from the standard.

Dangerous compiler options

gcc options and

Analysis

Description of the option taken from the gcc manual (see attachment on Porting to gcc 4 (Mandatory Changes for VLT2009)):
-traditional: Formerly, these options caused GCC to attempt to emulate a pre-standard C compiler. They are now only supported with the '-E' switch. The preprocessor continues to support a pre-standard mode. See the GNU CPP manual for details.
-traditional-cpp: Try to imitate the behavior of old-fashioned C preprocessors, as opposed to ISO C preprocessors.

Solution

The option has been removed form the .

gcc option

Analysis

Description of the option taken from the gcc manual (see attachment on Porting to gcc 4 (Mandatory Changes for VLT2009)):
-fpermissive: Downgrade some diagnostics about nonconforming code from errors to warnings. Thus, using '-fpermissive' will allow some nonconforming code to compile. The gcc manual discourages the usage of this option:
We do not recommend using '-fpermissive' to work around invalid code, and it will also only catch cases where functions in base classes are called, not where variables in base classes are used (...). The option was added to the to cope with certain problems caused by stricter handling of the gcc compiler.

Solution

All concerned sources have been adapted to comply with the standard and the option removed from the VLT2009 . One example for the usage of not standard-compliant code is the usage of a so called "extra qualification" in class definitions (see Warning: extra qualification on member).

gcc option

Analysis

The compiler option is not supported by older compiler versions, especially not by the gcc compiler used with VxWorks 5.5.

Solution

If LCU source code is to support both VxWorks version 5.5 and 6 the settings in must not use the gcc option by default for all LCU sources. If this option is required in the then it has to be used in a case differentiation depending (explicitly or implicitly) on the used VxWorks version. The vltMakefile has been updated and the settings now depend on the WIND_BASE value. For VxWorks version 5.5 the gcc option is not used.

List of warnings

Here is a collection of warnings, extracted from the VLTSW integration and filtered for identifier name etc.

warning: 'XXX' defined but not used

Analysis

The majority of this problem's occurrences is owed to the change in the rcsId handling ( ) - see also Porting to gcc 4 (Mandatory Changes for VLT2009).
The automatic conversion could add the macro only to all definitions where the file has been already included. In all other cases the decision whether to add the (missing) include file or otherwise the file must be taken by the developper.
A total of 140 files in the VLT Common Software is still affected.

Solution

Add include file or (if may not be used in specific cases) to all affected source files and add to the definition.

warning: deprecated conversion from string constant to 'char*'

Analysis

Building the VLTSW this warning occured over 5121 times in 326 files. The warnings are due to declarations like: char *aVar = "aString"; or void aFunc( char *aVar) { ... } aFunc( "aString" ); And for example the definition of rcsId, which appears 187 times: ATTRIBUTE_UNUSED static char *rcsId="@(#) $Id: ...";

Solution

All source code has to be aligned to comply with the standards. The way to fix this is to replace by const char pointers : const char *aVar = "aString"; or void aFunc( const char *aVar) { ... } Ex: case rcsId : ATTRIBUTE_UNUSED static char *rcsId="@(#) $Id: ..."; should be replaced by ATTRIBUTE_UNUSED static const char *rcsId="@(#) $Id: ..."; However, the large number of ocurrences in the sources require an automated solution. For the case of rcsId, the following sed command can be used: find . -name "*.C" -exec sed -i -e 's/ATTRIBUTE_UNUSED static char \*rcsId/ATTRIBUTE_UNUSED static const char \*rcsId/' {} \;

warning: extra qualification 'XXX' on member 'YYY'

Analysis

First a code example demonstrating the "extra qualification": class XXX { int XXX::YYY(int parameter); int ZZZ(int parameter); } In this example the method is defined with the preceding class name thus specifying a superfluous "extra qualification".
The second method is defined correctly. gcc 4 does not permit this "extra qualification" any longer (in contrast to earlier compiler versions) and the compilation fails with the error message .
However, the compiler can be forced to accept such non-conforming code by specifying the gcc option -fpermissive. Then the error is turned into a warning and the compilation does not fail.

Solution

Removing the "extra qualification" is an essential step to make the source code standard-compliant.

warning: pointer targets ... differ in signedness

Analysis

There were 2532 warnings of this type, in different forms:
  • warning: pointer targets in assignment differ in signedness
  • warning: pointer targets in initialization differ in signedness
  • warning: pointer targets in passing argument 1 (2, 3, 4, 5, 6, 7, 8) of 'XXX' differ in signedness
The majority of these warning are produced by the usage of vltBYTES (defined as unsigned char in vltPortGeneral.h) where a char* is expected (see SPR VLTSW20080211). For example: logManager.c:284: warning: pointer targets in passing argument 1 of 'strcpy' differ in signedness

Solution

The following has been implemented to get rid of the warning :
  • type vltINT8 changed, defined now as signed char
  • type vltBYTES unchanged, defined as unsigned char
  • type vltSTRING, defined as char (see SPR VLTSW20090007), added

warning: there are no arguments to 'XXX'....

Complete message: warning: there are no arguments to 'XXX' that depend on a template parameter, so a declaration of 'XXX' must be available

Analysis

The problem is explained here: http://gcc.gnu.org/onlinedocs/gcc/Name-lookup.html In short, the C++ compiler now follows the C++ standard that prescribes that all names that are not dependent on template parameters are bound to their present definitions when parsing a template function or class.
Only names that are dependent are looked up at the point of instantiation.

Solution

In order to make it clear that you want the member of the base class, you need to defer lookup until instantiation time, at which the base class is known. For this, you need to access i in a dependent context, by either using this->i (remember that this is of type Derived
Copyright © 2008-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding DOE (ex-SDD) TWiki? Send feedback

Welcome to LinuxQuestions.org, a friendly and active Linux Community.

You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!

Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.

Are you new to LinuxQuestions.org? Visit the following links:
Site Howto | Site FAQ | Sitemap | Register Now

If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.

Having a problem logging in? Please visit this page to clear all LQ-related cookies.


Introduction to Linux - A Hands on Guide

This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter. For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.


Click Here to receive this Complete Guide absolutely free.

0 comments

Leave a Reply

Your email address will not be published. Required fields are marked *