From: Thomas Matthews (Thomas_MatthewsHatesSpam_at_sbcglobal.net)
Date: Wed, 22 Oct 2003 16:42:29 GMT
> class foo
> char table;
> for(int index=0; index < 64; index++)
> table[index] = index;
Here you assign an "int" value (index)
into a "char" type (table).
In many systems, a char type is smaller than an
int type. In these systems, an "invisible" truncation
or conversion will take place. Ugly, very ugly.
for (char index = 0; index < 64; ++index)
table[index] = index;
> in the main program I do ;
> foo test;
> nothing more, just run the constructor
> it seems to run through the above loop coz I get 'Press any key to continue'
> then I get popup box saying test.exe has encountered a problem and needs to
> close. We are sorry for the inconvenience.
> If I remove the for loop in the constructor everything runs smoothly.
One item that others haven't mentioned is that you
declare the array as type "char" while you assign it
"int" values. Although many compilers may not issue a warning,
I believe it should, and you should turn up the warning levels.
In your main() program, insert the following:
std::cout << "Size of char: " << sizeof(char) << "\n";
std::cout << "Size of int: " << sizeof(int) << "\n";
-- Thomas Matthews C++ newsgroup welcome message: http://www.slack.net/~shiva/welcome.txt C++ Faq: http://www.parashift.com/c++-faq-lite C Faq: http://www.eskimo.com/~scs/c-faq/top.html alt.comp.lang.learn.c-c++ faq: http://www.raos.demon.uk/acllc-c++/faq.html Other sites: http://www.josuttis.com -- C++ STL Library book