avr-libc-dev
[Top][All Lists]
Advanced

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

Re: [avr-libc-dev] [patch #6418] Yet another delay routines


From: Carlos Lamas
Subject: Re: [avr-libc-dev] [patch #6418] Yet another delay routines
Date: Tue, 11 Mar 2008 01:09:36 +0100

Hello,

I have not considered __builtin_constant_p(), I tend to forget all those built in GCC functions after several failed attempts to use some of them. I have been turning around your idea last days.

In my opinion the biggest weakness of my first proposed code is the obscure error message when the parameter passed is not a constant. It should help to present a clearer error message when the parameter is invalid. __builtin_constant_p() facilitates the testing but it does not allow to stop the compilation process by itself, and #error directive cannot be used in a macro expansion. The solution seems to use __builtin_constant_p() to conditionally compile the assembler directive '.error'. This way, when a non constant argument is entered the file compiles ok but the assembler stops showing errors. When combined with '.print' directive, and __FILE__ and __LINE__ symbols to clone an ordinary error message to help IDEs identifying the source of the error *.c file, the result looks pretty good. This method also allows to perform additional range checking in the delay parameter.

__builtin_constant_p() behaves slightly different depending on the optimization level selected. With -O0 'const' qualified variables are not recognized as constant values, and with optimization enabled 'const' variables are seen as any other numerical constant. This introduces a little asymmetry.

In a couple of days or so I will complete testings and doxygen comment checking, to upload the new version to Savannah.

Best regards,

Carlos.


[...]

David Brown wrote:
Carlos Lamas wrote:
<snip>

Problem 2. The proposed solution is to check the constant parameter passed against an inline assembler constraint in an empty dummy asm() instruction. This also requires to transform the inline function in a macro. Passing a variable as the argument to the macro generates an error a bit obfuscated.

<snip>

Hi Carlos,

I don't know if you've considered it, but the __builtin_constant_p(exp) function might be a better way to check for constant parameters:

http://gcc.gnu.org/onlinedocs/gcc-4.2.2/gcc/Other-Builtins.html

[...]





reply via email to

[Prev in Thread] Current Thread [Next in Thread]