getting lots of warnig during compilation On soalris 5.8 using C++ (5.5)

Hi ,

I am trying to compile code in 64 bit mode on Solaris 5.8 using compiler C++(5.5 Patch 113817-14 2005/07/19) .

It compiles sucessfully with lots of warning . Also I am using option warning level (+w2) with following warnings

Warning:Conversion of 64 bit type value to "int" causes truncation

Warning:Conversion of 64 bit type value to "bool" causes truncation.

Warning: Conversion of 64 bit type value to "unsigned" causes truncation.

Warning: Conversion of 64 bit type value to "int" causes truncation.

Warning: Conversion of 64 bit type value to "unsigned short" causes truncation.

Warning: Conversion of 64 bit type value to "short" causes truncation.

After that libraries build sucessfully but some of the test cases are failed.

So in order to correct these warning what shall I do?

Thanks in advance

-Riaj

[900 byte] By [koresha@123] at [2007-11-26 9:45:32]
# 1

64 bit mode implies LP64 model, which stands for smth like "Long and Pointers are 64 bits". Other data types' size remains the same as in ILP32 data model, so when you assign long to int, there could be data loss.

There's good article on this matter: http://developers.sun.com/prodtech/cc/articles/ILP32toLP64Issues.html

MaximKartashev at 2007-7-7 0:49:19 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 2

Adding to Maxim's comments:

The +w2 option give you a lot of warnings you probably don't care about. It is intended to warn about picky portability issues when you need to use the code on different platforms with different compilers.

If your code was intended for 32-bit compilation and you simply recompile in 64-bit mode, you need look into the issues descibed in the porting paper that Maxim pointed to.

In addition, use the C++ compiler option -xport64 instead of +w2. The -xport64 option reports on issues where 64-bit compilation can produce different results from 32-bit compilation.

clamage45 at 2007-7-7 0:49:19 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 3
I am getting same warning for -xport64 as I got in +w2.Can you please send some examples to resolve the problem . From the previous URL I didn't find much.Thanks-Riaj
koresha@123 at 2007-7-7 0:49:19 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 4
The C++ Users Guide documentation for the -xport option http://docs.sun.com/source/819-3690/Comp_Options_App.htmlhas examples of the warnings you are getting, with explanations and examples.
clamage45 at 2007-7-7 0:49:19 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 5

Hi ,

I am defined two member function in a class i.e

PrintMy(char*, int, int&);

and

PrintMy(char*, unsigned int,int&);

during compilation I am getting ambiguity error for overloading this function

Also I am using compiler CC: Sun C++ 5.5 Patch 113817-14 2005/07/19

Thanks in advance

-Riaj

koresha@123 at 2007-7-7 0:49:19 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 6

The error is just. It is worth reading a book on C++, for example, this one: http://www.research.att.com/~bs/3rd.html

...

Oops, mixed this up with another C++ feature. I guess it's me who needs to read Stroustrup one more time... :-)

Message was edited by:

MaximKartashev

MaximKartashev at 2007-7-7 0:49:19 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 7

You can declare those two functions, and they can be distinguished in function overloading. For example:

[code]

struct T {

PrintMy(char*, int, int&); // #1

PrintMy(char*, unsigned int,int&); // #2

};

int main()

{

char str[10];

T t;

int x;

t.PrintMy(str, 3, x); // calls #1

t.PrintMy(str, 3u, x); // calls #2

}

[/code]

You can compile this code (using -c) without an error message.

Please show an example of code that give an ambiguity error message.

clamage45 at 2007-7-7 0:49:19 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 8

Hi ,

Getting overloading ambiguity

int myreplaceStr(String &str,

const Char *searchStr,

const UChar *replaceStr = NULL);

int myreplaceStr(string &str,

const Char *searchStr,

const Char *replaceStr = NULL,

Locale* Locale = G_CurrLocale);

template <typename char_type>

int myreplaceStr(char_type *str,

const char_type *searchStr,

const char_type *replaceStr,

//const char_type *replaceStr = NULL,

Locale* Locale = G_CurrLocale)

{

}

if I called this function as myreplaceStr( recipientsList, "'\"");

and when I compile this function I am getting error in overloading ambiguity

it couldn't resolve the overloading problem .

if I explicit write as myreplaceStr( recipientsList, "'\"",NULL);

then it will resolve .

Is there any specific way to call this function and rest of the values are constant

then how I will write the function so that I will not explicit pass the parameter

-Riaj

koresha@123 at 2007-7-7 0:49:19 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 9

Function overloading depends very strongly on the exact types involved. Seemingly small changes in type definitions can radically affect the results of function overload resolution. We need the answers to fhe following questions:

What is type Char?

What is type UChar?

What is type string?

What is type String?

What is NULL?

I will assume the following:

#include <string>

using std::string;

typedef string String;

typedef char Char;

typedef unsigned char UChar;

// NULL is from header <string> or some other standard C++ header.

If any of those assumptions is wrong, the discussion below might not apply.

Both of the non-template myreplaceStr functions can be called with two arguments, since the remaining parameters have default values. The first two parameters have the same type.

Therefore, if you provide only two arguments, the compiler cannot choose between the two functions..

But adding a third argument NULL does not affect the overload resolution problem. Either of the non-template functions can still be called, because a null pointer is an exact match to either Char* or UChar*.

So if your example compiles after adding NULL as the 3rd argument, either you have found a compiler bug, or some of the assumptions I made for this discussion are not correct.

I can give you a more complete answer if you post a stand-alone example that can actually be compiled and shows where you do and do not get an ambiguity error message.

clamage45 at 2007-7-7 0:49:19 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 10

Yes,

Your assumption for data type is correct

here is the details of header/cpp file

Please provide me some generic calling mechanism

[b]my.h[/b] contians the following details

int ReplaceStr(const char *oldStr,

char *newStr,

int &newLen,

const char *searchStr,

const char *replaceStr = NULL,

int maxLen = -1,

Locale* bbLocale = G_CurrLocale);

int ReplaceStr(const char *oldStr,

char *newStr,

int &newLen,

const char *searchStr,

const char *replaceStr,

int maxLen,

int start,

int replaces,

BOOLEAN_ useOrginalSearchStr = FALSE,

Locale* bbLocale = G_CurrLocale);

int ReplaceStr(const UChar *oldStr,

UChar *newStr,

int &newLen,

const UChar *searchStr,

const UChar *replaceStr = NULL,

int maxLen = -1,

Locale* bbLocale = G_UTF16Locale);

int ReplaceStr(const UChar *oldStr,

UChar *newStr,

int &newLen,

const UChar *searchStr,

const UChar *replaceStr,

int maxLen,

int start,

int replaces,

BOOLEAN_ useOrginalSearchStr = FALSE);

template <typename char_type>

int ReplaceStr(char_type *str,

const char_type *searchStr,

const char_type *replaceStr = NULL,

Locale* bbLocale = G_CurrLocale)

{

int len = BBWorstCaseReplaceResultLen(BBStrlen(str), searchStr, replaceStr);

char_type tempBuf[1024];

char_type *tempPtr = tempBuf;

if (len > 1023)

tempPtr = new char_type[len + 1];

int ret = ReplaceStr(str, tempPtr, len, searchStr, replaceStr, -1, bbLocale);

if (ret) BBStrcpy(str, tempPtr);

if (tempPtr != tempBuf)

DELETEARR(tempPtr);

return ret;

}

int ReplaceStr(String &str,

const UChar*searchStr,

const UChar*replaceStr = NULL);

int ReplaceStr(string &str,

const char *searchStr,

const char *replaceStr = NULL,

Locale* bbLocale = G_CurrLocale);

int ReplaceStr(RWCString &str,

const char *searchStr,

const char *replaceStr = NULL);

and I called "ReplaceStr" in main() of file [b]my.cpp[/b]

i.e

#include "my.h"

main()

{

char* recipientsList = NULL ;

...

ReplaceStr( recipientsList, "'\"");

...

}

during compilation I am getting the following error

"my.cpp", line 8: Error: Could not find a match for ReplaceStr(char*, const char[3]).

1 Error(s) detected.

*** Error code 1

make: Fatal error: Command failed for target `my.o'

Thanks in Advance

-Riaj

koresha@123 at 2007-7-7 0:49:19 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 11
Sorry, there are too many undefined types and objects. Please provide a complete example that can be compiled, except for the one error message that you are concerned about.
clamage45 at 2007-7-7 0:49:19 > top of Java-index,Development Tools,Solaris and Linux Development Tools...