[U-Boot] [PATCH 1/2] FAT: remove ifdefs to make the code more readable

Marek Vasut marex at denx.de
Thu Dec 13 14:19:58 CET 2012


Dear Richard Genoud,

> 2012/12/13 Marek Vasut <marex at denx.de>:
> > Dear Richard Genoud,
> > 
> >> 2012/12/13 Marek Vasut <marex at denx.de>:
> >> > Dear Richard Genoud,
> >> > 
> >> >> ifdefs in the code are making it harder to read.
> >> >> The use of simple if(VFAT_ENABLED) makes no more code and is cleaner.
> >> >> (the code is discarded by the compiler and linker instead of the
> >> >> preprocessor.)
> >> >> 
> >> >> and bonus, now the code compiles even if CONFIG_SUPPORT_VFAT is not
> >> >> defined.
> >> >> 
> >> >> Signed-off-by: Richard Genoud <richard.genoud at gmail.com>
> >> >> ---
> >> >> 
> >> >>  fs/fat/fat.c       |   55
> >> >> 
> >> >> +++++++++++++++++++++++++++------------------------
> >> >> fs/fat/fat_write.c | 11 ++-------
> >> >> 
> >> >>  2 files changed, 32 insertions(+), 34 deletions(-)
> >> >> 
> >> >> diff --git a/fs/fat/fat.c b/fs/fat/fat.c
> >> >> index 393c378..c79e3e3 100644
> >> >> --- a/fs/fat/fat.c
> >> >> +++ b/fs/fat/fat.c
> >> >> @@ -34,6 +34,12 @@
> >> >> 
> >> >>  #include <malloc.h>
> >> >>  #include <linux/compiler.h>
> >> >> 
> >> >> +#ifdef CONFIG_SUPPORT_VFAT
> >> >> +#define VFAT_ENABLED 1
> >> >> +#else
> >> >> +#define VFAT_ENABLED 0
> >> >> +#endif
> >> > 
> >> > [...]
> >> > 
> >> > Make it static const int maybe ?
> >> 
> >> I hesitate to make them static const, I can't figure why it's better
> >> to use static const variable instead of defines.
> >> Could you enlighten me ?
> > 
> > Because you get the type-checking. Preprocessor is evil ;-)
> > 
> > Best regards,
> > Marek Vasut
> 
> Ok ! Thanks, I'll resend it with the change.

Thanks!

Yes, preprocessor eats kittens too ;-)

Best regards,
Marek Vasut


More information about the U-Boot mailing list