C++

Objectives :

  • Watch your codes and know your environment.
 

All the software or program you use, would be updated to a revised version  from time to time.

Very often, in some  rare and few isolated instances, one software accepted old codes, mix-match of new or old platforms, backward-compatible or more forgiving over the other. And the same software at a later update, mysteriously displayed runtime errors.

The following code snippet, strncat(..,..,..) should throw a run time error, as the size of the source string was larger than the destination string.

char charray1[13]= "Hello Array";
char charray2[20]=" Another Array";
//function prototype is , char * strncat ( char * destination, char * source, size_t num );
// code that should complain
strncat (charray1, charray2,20);

Note  that Eclipse 3.3.2 IDE in this workstation, windows XP Pro 32 bit, did display the runtime error, as expected. Where as Quincy 2005 compiler in the same computer did not complain; and it should have displayed an error as the size of destination, is smaller than the size of the input string.

The same code, did compile in  Quincy 2005 software, installed in the same workstation.

To my surprise, the above codes worked in Eclipse 3.3.2 IDE installed in another workstation ( Windows Ultimate 64 bit), and  displayed all outputs. We should have seen error message, while running the faulty codes, as the size of the destination is smaller than the feed.

char charray1[13]= "Hello Array";
char charray2[20]=" Another Array";
// char * strncat ( char * destination, char * source, size_t num );
// code that should complain
strncat (charray1, charray2,20); 

Error correction: