Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » AVR-GCC
  • » [avr-gcc-list] Naming styles and conventions [RSS Feed]

#1 Oct. 28, 2005 12:31:08

David B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] Naming styles and conventions


Hi everyone,I'm looking to define a style to use in my code and I would prefer tofollow the conventions used in avr-libc.What's the meaning behind the __ and _ that we can find before/afterfunctions and variables names in avrlibc?__file
__boot_eeprom_spm_safe
_BV()
__SPM_REG
__attribute__
_delay_us(double __us)I also found that macros are sometimes uppercased and lowercased. Is therea different meaning behind this or just a mix of styles?#define eeprom_is_ready() bit_is_clear(EECR, EEWE)
#define _EEGET(var, addr) (var) = eeprom_read_byte ((uint8_t *)(addr))

If someone has a nice C style guide to share, I'm interested too.

Thanks,
David Bourgeois


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#2 Oct. 28, 2005 13:08:38

Joerg W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] Naming styles and conventions


"David Bourgeois" <> wrote:

> What's the meaning behind the __ and _ that we can find before/after
> functions and variables names in avrlibc?

To protect them from collisions with the application name space.

Anything starting with two underscores, or one underscore followed by
a letter is reserved ``for the implementation''.

Typically, in avr-libc two underscores are used for completely
internal stuff, one is used for stuff that is meant to be used by
application writers but which should be ensured to not cause a
collision with anything in the application itself.

(GCC also exports certain things with two underscores to application
writers, like __attribute__, or __asm__.)

> I also found that macros are sometimes uppercased and lowercased. Is
> there a different meaning behind this or just a mix of styles?

Normally, macros with side effects or that define constants are
written in all-CAPS. That's so the eye can easily catch them.
Function-like macros with lower-case letters must behave completely
like a function, in particular they must not evaluate their arguments
more than once.

> #define eeprom_is_ready() bit_is_clear(EECR, EEWE)
> #define _EEGET(var, addr) (var) = eeprom_read_byte ((uint8_t *)(addr))

eeprom_is_ready() behaves like a normal function.

_EEGET is a compat macro for IAR only, so we had to stick to their
naming convention. Note that this macro does not behave like a
function anyway, as it returns the value into its first argument
(without the need to pass a pointer reference or such). The avr-libc
macro with the same functionality is eeprom_read_byte() which again
behaves like a function (i.e. it truely "returns" the value read from
the EEPROM).

--
J"org Wunsch Unix support engineer
http://www.interface-systems.de/~j/_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

  • Root
  • » AVR-GCC
  • » [avr-gcc-list] Naming styles and conventions [RSS Feed]

Board footer

Moderator control

Enjoy the 18th of November
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support