lmi
[Top][All Lists]
Advanced

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

[lmi] dealing with standard C functions implemented as macros


From: Vadim Zeitlin
Subject: [lmi] dealing with standard C functions implemented as macros
Date: Sun, 23 Mar 2008 21:45:12 +0100

 Hello,

 I'd like to know if there is an official policy for using standard
functions which can be implemented as macros. The case in point is the use
of ferror() in md5.cpp which does

        if (n == 0 && std::ferror (stream))

The problem is that when ferror() is a macro, this doesn't compile (FYI
the expansion of std::ferror(stream) in my particular case becomes
"std::((stream)->_flag & _IOERR)" which is syntactically invalid).

 I see 2 possible solutions:

1. Do an "#undef ferror" to force the use of a function version. I'm not
   100% sure if an implementation is allowed to define ferror() solely as
   a macro but I don't think, even though I can't find the exact reference
   right now I believe that the function version must be always provided.
   But if there is any uncertainty about this we could, of course, use this
   #undef for MSVC only which is known to provide both macro and function
   versions of ferror().

2. Remove "std::" and include stdio.h instead of cstdio header. AFAICS
   there can be no problems at all with doing this and, while it probably
   doesn't matter much, we'd use more efficient macro implementation of
   ferror() when available.


 Personally I prefer (2) as IMO using cstdio doesn't bring any real
benefits compared to stdio.h (and FWIW I never understood the C++ standards
committee decision to provide these wrapper headers) but please let me know
if you prefer (1) or if you see an even better alternative solution.

 Thanks,
VZ





reply via email to

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