[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-chat] ensuring that _delay_us() gets a compile-time double constant
From: |
Britton Kerin |
Subject: |
[avr-chat] ensuring that _delay_us() gets a compile-time double constant |
Date: |
Tue, 2 Dec 2014 14:12:55 -0900 |
I'd like to say:
#define USUALLY_INT_CONSTANT 42
int val_for_expression_needing_to_stay_int = USUALLY_INT_CONSTANT * foo_int;
_delay_us (USUALLY_INT_CONSTANT);
So the questions:
1. Does _delay_us() need a double const, or is an int const guaranteed
to work? The avr libc manual just says "known const" in one place,
but the signature calls for a double.
2. Can the compiler be relied on to turn USUALLY_INT_CONSTANT to a double
at compile time? Where is this guarantee written down?
3. Is there something I can write in the code to check that things are
correct at compile-time? I've looked a bit at _Static_assert() and
__builtin_constant_p() but I'm not sure what I want that is gauranteed to
work, or if the builtin check that the modern GCC is doing is gauranteed
to work? It generates output like this:
In file included from one_wire_slave.c:8:0:
/home/bkerin/opt/avr/avr/include/util/delay.h: In function ‘ows_write_bit’:
/home/bkerin/opt/avr/avr/include/util/delay.h:163:28: error:
__builtin_avr_delay_cycles expects a compile time integer constant
__builtin_avr_delay_cycles(__ticks_dc);
^
make: *** [one_wire_slave.o] Error 1
- [avr-chat] ensuring that _delay_us() gets a compile-time double constant,
Britton Kerin <=