[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Debian coding style?



In article <373557C5.F4D4C150@ulink.net>, Paul Lowe  <spazz@ulink.net> wrote:
>>>19. Comparisons for equality against a constant value should list the
>>>constant value first. Its easy to miss one of the equals signs - this way
>>>the compiler will catch it if you do.
>>>
>>>eg. if (-1 == m_nResult) rather than if (m_nResult == -1)
>>
>>This isn't the only instance of Corel forcing the compiler to reject
>>invalid code.  You should see how they verify the sizes of data types!
>
>How do they do it?

(from memory, untested, but you'll get the idea):

	#define COMPILER_ASSERT(foo) \
		do { \
			enum { \
				bar = 1 / (foo) \
			}; \
		} while (0)

	COMPILER_ASSERT(sizeof(void*) == sizeof(long));

It's supposed to cause the compiler to die with a division by zero error
when determining the value of 'bar' unless 'bar' is true.  'enum'
forces the compiler to determine the expression value at compile time.
gcc complains that the initializer for 'bar' is not a constant integer
or something, but it fails in all the right places.

The problems with this code are:

1.  You can't use it in generic system .h files, the single place where
it's most useful, because it would be code outside of a function, and

2.  You can't use it more than once because of multiply-defined enumerated
types.  Or something, I forget what at the moment.

We decided that autoconf was better at that sort of thing anyway, and that
we should not be feeding 64-bit-unclean code to an Alpha.

-- 
Zygo Blaxell, Linux Engineer, Corel Corporation.  zygob@corel.ca (work) or
zblaxell@furryterror.org (play).  Corel may disagree with my opinion (above).
Linux naga 2.0.36 #1 Dec 29 13:11 EST 1998 up 4 days, 14:10
Linux mokona 2.2.2 #1 Mar 1 03:05 EST 1999 i586 up 3 days, 5:37


Reply to: