RE: Need suggestion for using intypes.h features in centos5 gcc 4.1.2 compiler version.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,
Hope doing great. I mimic the production code here and would like to know the reason why gcc 8.2 is not throwing any warnings. We provided -Wall and -Wextra. Please let me know the right flag to show the warning during compilation time. Thanks

#include <iostream>
#include <string>
using namespace std;

class Sample {
    string name ;
  public:
     void setData(string value)  { name = value; }
    string getName() const { return name; }                                        -- Returns a copy of the string
    const char* getName1() const { return name.c_str(); }              -- Returns a Char* to the actual instance variable
    const char * getDestination()    { return getName().c_str(); }.   – Issue is getName() returns a copy of the actual string which is local to this function. Once the function goes out of scope it return junk values. Why the compiler is not throwing any warnings.
};

int main () {
  Sample sample;
  sample.setData("ROUTEX_CI");
  cout << "String Return Name: " << sample.getName() << "\n";
  cout << "Const Char Return Name with Instance Variable: " << sample.getName1() << "\n";
  cout << "Const Char Return With Temp Variable Created: " << sample.getDestination() << "\n";
  return 0;
}


Different in output between CentOS7/gcc 8.2 compiler and CentOS5/gcc 4.2 compiler for the same code.

CentOS7/gcc 8.2 compiler:
String Return Name: ROUTEX_CI
Const Char Return Name with Instance Variable: ROUTEX_CI
Const Char Return With Temp Variable Created: 7���-

CentOS5/gcc 4.2 compiler:
String Return Name: ROUTEX_CI
Const Char Return Name with Instance Variable: ROUTEX_CI
Const Char Return With Temp Variable Created: ROUTEX_CI


-----Original Message-----
From: Kannuswamy, Nanthakumar
Sent: Wednesday, July 29, 2020 7:38 PM
To: 'Jonathan Wakely' <jwakely.gcc@xxxxxxxxx>
Cc: gcc-help@xxxxxxxxxxx; Ramakrishnan, Murugan <murugan.ramakrishnan@xxxxxxxxxx>
Subject: RE: Need suggestion for using intypes.h features in centos5 gcc 4.1.2 compiler version.

Thanks for your help.


Internal Use Only

-----Original Message-----
From: Jonathan Wakely <jwakely.gcc@xxxxxxxxx>
Sent: Wednesday, July 29, 2020 4:19 PM
To: Kannuswamy, Nanthakumar <nanthakumar.kannuswamy@xxxxxxxxxx>
Cc: gcc-help@xxxxxxxxxxx; Ramakrishnan, Murugan <murugan.ramakrishnan@xxxxxxxxxx>
Subject: Re: Need suggestion for using intypes.h features in centos5 gcc 4.1.2 compiler version.

On Wed, 29 Jul 2020 at 21:56, Kannuswamy, Nanthakumar via Gcc-help <gcc-help@xxxxxxxxxxx> wrote:
>
> Hello All,
>
> We would like to use PRIxxx macros which is defined in <inttypes.h>
> (introduced in C99)  in our c++ code base which is running on
> centos5/gcc 4.1.2.  When we compiling the following program using gcc
> centos5/4.1.2 its compiled successfully
>
> #include <inttypes.h>
> #include <stdio.h>
>
> Int main() {
> Int val = 10;
> printf("Value is %" PRId32, val);
> return 0;
> }
>
> $> gcc PRImacros.c
> Compiled and run successfully.
>
>
> But at the same time, if we compile above program using centos5/g++
> 4.1.2 comes as part of bundled gcc 4.1.2 package,  we got the
> following error
>
> $> g++ PRImacros.cpp
> PRImacros.cpp: In function 'int main()':
> PRImacros.c:8: error: expected `)' before 'PRId32'
>
> Since this PRIxxx is introduced in c99, we tried in the following way
> too, but got the error
>
> $> g++ -std=c99 PRImacros.cpp
> cc1plus: warning: command line option "-std=c99" is valid for C/ObjC
> but not for C++
> PRImacros.c: In function 'int main()':
> PRImacros.c:8: error: expected `)' before 'PRId32'
>
> So our question is, Is it possible to use PRIxxx macros in c++ code running on centos5/g++ 4.1.2? If so, how to use it.

It should work if you use g++ -D__STDC_FORMAT_MACROS

The C99 standard said that the macros should not be defined for C++ unless that macro is defined, and the libc headers on CentOS 5 follow that rule. Later C standards removed that rule, so that the macros should be unconditionally defined for C++ programs.


This communication is the property of E*TRADE Financial Holdings, LLC and its affiliates and does not constitute an offer to sell or the solicitation of an offer to buy any security. It is intended only for the person to whom it is addressed and may contain information that is privileged, confidential, or otherwise protected from disclosure. Distribution or copying of this communication, or the information contained herein, by anyone other than the intended recipient is prohibited. If you have received this communication in error, please immediately notify E*TRADE Financial Holdings, LLC at (800) 387-2331, and delete and destroy any copies hereof.





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux