[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug report
From: |
Ender |
Subject: |
bug report |
Date: |
Mon, 02 Apr 2001 18:32:23 -0300 |
hi,
I've got a bug trying to compile the following function:
//===============================
unsigned long int geraKey(char *name)
{
union
{
unsigned long int key;
unsigned short int key_short[2];
};
key_short[0] = strlen(name);
key_short[1] = 0;
/**** THE BUG WAS GENERATED BY THE FOLOWING LINE ****/
for(int i=0;i<key_short[0];i++)
{
key_short[1] += (((unsigned short int) ((unsigned char)name[i])) & 0xff);
}
return key;
}
//===============================
the compile options are:
g++ -Wall -lnsl -lpthread -lsocket -fexceptions -o source.cpp -O
to compile the program without errors, I've changed the code to:
(this code is OK)
//===============================
unsigned long int geraKey(char *nome)
{
unsigned short int n;
union
{
unsigned long int key;
unsigned short int key_short[2];
};
key_short[0] = strlen(nome);
key_short[1] = 0;
n = strlen(nome);
for(int i=0;i<n;i++)
{
key_short[1] += (((unsigned short int) ((unsigned char)nome[i])) & 0xff);
}
return key;
}
//===============================
[]s'
Ender