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

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

[avr-libc-dev] How to deal with eeprom.h "unused code" warning?


From: Bob Paddock
Subject: [avr-libc-dev] How to deal with eeprom.h "unused code" warning?
Date: Thu, 30 Aug 2007 14:08:51 -0400
User-agent: Opera Mail/9.10 (Win32)


/*
In the program below, if I do in the Makefile:

CFLAGS += -Wunreachable-code

I get a warning about unreachable code in lines 234 and 255
of eeprom.h, with 4.1.2 (WinAVR 20070525rc2).

Anything I can do about that other than not use -Wunreachable-code?
Anyway to apply -Wunreachable-code to my code but not libraries?

In my own code I try to run with the full suite of GCC warnings/errors enabled,
but not sure how to handle things when a library triggers a warning?
It is policy to have no warning messages in code so "ignore it" is
not an option.

# -Werror : Make all warnings into errors.
CFLAGS +=  -Werror

# -pedantic : Issue all the mandatory diagnostics listed in the C
# standard. Some of them are left out by default, since they trigger frequently
# on harmless code.
#
# -pedantic-errors : Issue all the mandatory diagnostics, and make all
# mandatory diagnostics into errors. This includes mandatory diagnostics that
# GCC issues without -pedantic but treats as warnings.
CFLAGS +=  -pedantic

#Warn if an undefined identifier is evaluated in an `#if' directive.
CFLAGS += -Wundef

#-Wunreachable-code
#Warn if the compiler detects that code will never be executed.
CFLAGS += -Wunreachable-code

*/

#include <avr/eeprom.h>
#include <stddef.h>
#include <stdint.h>

typedef struct EEP
{
uint16_t version_u16; /* Version number of this structure for Flash compatibility tests */

  uint8_t  var_a_u8;

uint16_t crc_u16; /* CRC value of this EEPROM structure, this must be last in the structure */
}EE_PROM;

#define SIZEOF(s,m) ((size_t) sizeof(((s *)0)->m))

#define EE_RD(M,D) eeprom_read_block(D, (const void *) offsetof(EE_PROM,M), SIZEOF(EE_PROM,M) ) /* Must #include <eeprom.h> to get eeprom_read_block() */
/* That is one long line, don't let your email program wrap it */

int main( void )
{
  uint8_t byte_u8, word_u16;

  EE_RD( var_a_u8, &byte_u8 );
  EE_RD( version_u16, &word_u16 );
}





reply via email to

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