Thomas Matthews <Th************ **********@sbcg lobal.net> writes:
Ashabul Yeameen wrote: Hi all,
I am writing a C program which at some certain steps needs to use the
wide character funcion fputwc() for giving utf-8 output. Since I want
to make the code more portable, I wrote my own fputwc() function. But
I want to use my own funcion in the case where the compiler does not
supply this funcion. Is there any way, i.e. any preprocessor
directive, to know whether the supports wide character or not.
-Yeameen
Perhaps:
#ifdef fputwc
#endif
????
Nope. The fputwc function may be implemented as a macro, but it
doesn't have to be. The #ifdef directive can't tell you whether a
function is defined, and there's no portable compile-time method for
determining whether a given function or type is defined.
As far as the standard is concerned, the wchar_t type isn't optional,
any more than size_t or int. It must be defined in <stddef.h>. This
is true both for C90 and for C99. If you're dealing with a compiler
that doesn't fully support either the C90 or the C99 standard, it's
likely to be missing other important features as well -- such as
prototypes. There are ways of writing code that will work under such
old implementations ; it's up to you to decide whether it's worth the
effort. (I think gcc is still designed to be compiled with pre-C89
compilers; you might look at the gcc sources for ideas.)
You may also need to worry about whehter fputwc() is going to give you
utf-8 output, even if it exists.
Probably your best approach is to use some small test programs to tell
you, by whether or not they compile, what features are supported. Try
compiling the test programs as part of your configuration process.
During configuration, you might generate your own C headers that you
include in your own code. (I think the GNU autoconf system does this
kind of thing; if you want to know more about that, you'll need to
read its documentation or find an appropriate newsgroup.)
--
Keith Thompson (The_Other_Keit h)
ks*@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"