Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Discrepancy in the solaris CC 5.3 and 4.2

Reply
Thread Tools

Discrepancy in the solaris CC 5.3 and 4.2

 
 
Pr
Guest
Posts: n/a
 
      01-08-2004
Hi -
I have a code that works very well on 4.2, but fails on 5.3.

Here's the description of the problem.

I use 'gperf' generated C++ files in my software that give diffrent
behavior with CC 5.3 and CC 4.2. The C++ file that has the bug, the
'bug.cxx' is attached in-line down.

'bug.cxx' ---> The C++ file generated from the 'gperf' file.

Please note that the following command line has been used for
generating
the C++ file from 'gperf' file :
gperf -a -o -G -LANSI-C -k 1 -N _isContainerWord
alfContainerWords.gperf > bug.cxx

Now, if we look in to the value of 'asso_values[(unsigned
char)str[0]]'
(at line number '51' in the file 'bug.cxx'), it gives different in
different result with CC 5.3 and CC 4.2 respectively. For an instance,
let's consider the value of 'str[0]' as 'i', then the values shows by
CC
4.2 binary are as follow :
Value of 'str[0]' ---> 'i'
Value of '(unsigned char)str[0]' ---> 'i'
Value of 'asso_values[(unsigned char)str[0]]' ---> '\0'
And these values is expected. But the binary with CC 5.3 showing
something different. The values shows by CC 5.3 are as follow :
Value of 'str[0]' ---> 'i'
Value of '(unsigned char)str[0]' ---> 'i'
Value of 'asso_values[(unsigned char)str[0]]' ---> '\024'
The first two values are fine, but the last one is not at all
expected.

For the CC5.3 compiled program the asso_values array never gets
initialised and points to the corrupted memory location from the very
beginning. It doesnot get re-initialised when I call the hash
function.

Any idea why this is so?
Appreciate your response,

=============
bug.cxx file
=============
/* ANSI-C code produced by gperf version 2.7.2 */
/* Command-line: /system/pkg/gperf/2.7.2/bin/sparc-sun-solaris2.8/gperf
-a -o -G -LANSI-C -k 1 -N _isContainerWord alfContainerWords.gperf */
#include <string.h>

#define TOTAL_KEYWORDS 6
#define MIN_WORD_LENGTH 2
#define MAX_WORD_LENGTH 11
#define MIN_HASH_VALUE 2
#define MAX_HASH_VALUE 11
/* maximum key range = 10, duplicates = 0 */

#ifdef __GNUC__
__inline
#else
#ifdef __cplusplus
inline
#endif
#endif
static unsigned int
hash (register const char *str, register unsigned int len)
{
static unsigned char asso_values[] =
{
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 2, 12, 12, 0, 12, 12, 0, 12,
12, 12, 12, 12, 12, 0, 0, 12, 0, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12
};
return len + asso_values[(unsigned char)str[0]];
}

static const char * wordlist[] =
{
"", "",
"to",
"",
"scan",
"limit",
"from",
"", "",
"violation",
"",
"information"
};

#ifdef __GNUC__
__inline
#endif
const char *
_isContainerWord (register const char *str, register unsigned int len)
{
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
{
register int key = hash (str, len);

if (key <= MAX_HASH_VALUE && key >= 0)
{
register const char *s = wordlist[key];

if (*str == *s && !strcmp (str + 1, s + 1))
return s;
}
}
return 0;
}
/* Wrapper function for _isContainerWord which gperf will generate */
const char* alfIsContainerWord(const char* name, int len)
{
return _isContainerWord(name, len);
}

// The following main() function has been added by Ujjwal
int main()
{
const char * name = "ibc"; int len = 11;
const char *ch;
ch = alfIsContainerWord( name, len);
return 0;
}

================================================== ==============================
-Pr
 
Reply With Quote
 
 
 
 
Ron Natalie
Guest
Posts: n/a
 
      01-08-2004

"Pr" <(E-Mail Removed)> wrote in message news:(E-Mail Removed) om...
> Hi -
> I have a code that works very well on 4.2, but fails on 5.3.


The Solaris 4.2 compiler is so off the standard language to be unusable.
It really didn't become usable until The 5.0 release. Even that release
is ancient (we've had 6.2 for years now and I suspect Sun has moved on
there as well).


> I use 'gperf' generated C++ files in my software that give diffrent
> behavior with CC 5.3 and CC 4.2. The C++ file that has the bug, the
> 'bug.cxx' is attached in-line down.


By the way heaven help you if you feed this code the string "" instead of
"ibc". The code would pass an invalid pointer to strcmp. I assume
this defect is part oif gperf's attempt to be cute rather than something
you introduced.

gperf IS outside the scope of this group, as are specific problems with
the SUNWspro compilers.

Other than that I can't see any problems off the top of my head.
I'd be more interested in these prints:

printf("%d\n", (unsigned char) str[0]);
Should be something like 105.

And I'd print out a few values of the table (asso_values[ 105]).

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Discrepancy between functional simulation and post-synthesissimulation when inferring a block-RAM Cesar VHDL 7 06-30-2010 03:54 AM
Apparant discrepancy between IE and FF browsers KiwiBrian HTML 8 10-30-2007 07:43 AM
Discrepancy between flow-packets and interface counter Garry Glendown Cisco 9 04-20-2005 08:38 PM
Exifer and Irfanview IPTC discrepancy Jonathan Berry Digital Photography 2 05-07-2004 11:39 PM
Time discrepancy between java and native Gopal Java 4 10-30-2003 05:37 PM



Advertisments