Re: [cc65] Common macros for dirent.d_type

From: Ullrich von Bassewitz <uz1musoftware.de>
Date: 2012-06-25 21:46:17
On Mon, Jun 25, 2012 at 09:40:11PM +0200, Groepaz wrote:
> in almost all cases i have seen these macros used in real code, they occur in
> a form like:
>
> if (_DE_ISREG(foo)) {
> 	bla
> }
>
> this will just work, always.

No, it will not. If the platform doesn't have dirent.d_type you will get
compile errors. To fix them, you will need something like

    #ifdef __ATARI__
        bla
    #else
        if (_DE_ISREG(e.d_type)) {
            bla
        }
    #endif

which is a lot worse than using

    #ifndef _DE_ISREG
        bla
    #else
        if (_DE_ISREG(e.d_type)) {
            bla
        }
    #endif

because it needs code changes for every new platform.

> for other occurances you'll get errors -
> coincedently for those who you will have to fix anyway no matter how you do
> it.

Nope. If the d_type field and the _DE_ISxxx macros are a requirement for all
platforms, the code will work everywhere - without any #ifs and without any
code changes for new platforms or compiler releases.

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz@musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Mon Jun 25 21:46:23 2012

This archive was generated by hypermail 2.1.8 : 2012-06-25 21:46:27 CEST