This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Bug finding problem



In C you have often Code like

--- example1 -----------------------------------------------

#ifdef  SIZEOF_LONG==8
typedef int    my_t;		// 64 bit systems
#else
typedef long   my_t		// 16/32 bit systems
#endif

extern void  foo ( my_t*  ptr );

...

    long  var;

    foo ( &var );		// bug, but well hidden on a 32 bit system

...

-----------------------------------------------------------

Although this is a serious bug you can't find this error until you try to
compile the code on a 64 bit system. You need 2 systems to compile-time-test
the code.

If you have more such constructs you need a lot of systems.

Is there any chance to make 'my_t' incompatible with it parent type
(like in Ada, where this is standard)? It would help to find a lot of
errors as early as possible.

--- example2 ----------------------------------------------

#include <stdint.h>

extern void  foo ( int64_t*  ptr );

...

    long  var;

    foo ( &var );		// bug, but well hidden on a 64 bit system

...

-----------------------------------------------------------

It is a shame how long such flaws can survive in a language like C
which are not possible in some other languages.

BTW: The problem is originally introduced by the C-flaw "conditional
translation of source code". Hides bugs and makes source less readable.

-- 
Frank Klemm



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]