473,598 Members | 2,844 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to determine (in compile time) whether a compiler supports wide characters or not

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
Nov 13 '05 #1
2 2006
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"
Nov 13 '05 #2
Keith Thompson <ks*@cts.com> wrote in message news:<lz******* *****@cts.com>. ..
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.


Yes, it is true. One of the two new compilers (which support wchar_t)
gave me utf-8 output. Probably it is dependent on the enviroment. btw,
I decided to use the follwing funcion (i found on the net) for getting
utf-8 output always.

-Yeameen

void fputwidec(int uni, FILE *fp)
{
if (uni < 0x80) {
fputc(uni, fp);
}
else if (uni < 0x800) {
fputc(0xC0 | uni>>6, fp);
fputc(0x80 | uni & 0x3F, fp);
}
else if (uni < 0x10000) {
fputc(0xE0 | uni>>12, fp);
fputc(0x80 | uni>>6 & 0x3F, fp);
fputc(0x80 | uni & 0x3F, fp);
}
}

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.)

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2639
by: Jonathan Mcdougall | last post by:
I started using boost's filesystem library a couple of days ago. In its FAQ, it states "Wide-character names would provide an illusion of portability where portability does not in fact exist. Behavior would be completely different on operating systems (Windows, for example) that support wide-character names, than on systems which don't (POSIX). Providing functionality that appears to provide portability but in fact
1
1726
by: Ashabul Yeameen | last post by:
I am writing a program which at some point need to call fputwc() function. But since I want to make this code portable I've decided to write my own fputwc() funcion where the compiler doesn't supply this funcion. But how to determine whether the compiler supports wide character or not (depending on which my funcion will compile). Is there any preprocessor directive? thanks in advance -Yeameen
2
4621
by: Glen | last post by:
I'm working on a custom assembly and I'm trying to figure out the best approach to handling known constraints within the assembly, once compiled, to alert the developer at compile time of a potential issue. For example, in the assembly I would like to add a constraint that states a particular property member of the class can not be equal to one other property. In standard coding I can throw an exception during run-time, but I would rather...
3
1513
by: Ys | last post by:
Hello, I have just migrated my project from VC6 to VC7.1. The project is mostly written in C, and some in C++ without MFC (Console application). I am on Win2k. I am not using managed code in VC7.1. I am experiencing VC7.1 C compile time taking about 4 times of VC6, though interestingly C++ stays within +10% margin. This is the same for debug, so it is not
12
3193
by: wxs | last post by:
Many times we have a bunch of enums we have from either different enums or the same enum that will have various numeric values assigned. Rarely will there be collisions in numbering between the enums. These enums you might imagine would be like OrderPrice=27, OrderQuantity=50, OrderSide=62. There may be a lot of these. So normally what we would have to do is store these in hash table so hashtable=value could be set with the value....
1
1600
by: Marcin Kalicinski | last post by:
Is there a way, using template metaprogramming techinques like e.g. SFINAE, to determine at compile time if a type supports certain operation (for example if operator == is defined for that type)? // Function for types supporting == template<class Tbool func(T t) { if (t == 3) return true; else
27
5587
by: CodeMonk3y | last post by:
gotta question on sizeof keyword does the sizeof keyword calcuates the size at compile time or run time ?? -- Posted on news://freenews.netfront.net - Complaints to news@netfront.net --
9
3932
by: Bill Cunningham | last post by:
I want to print out the Chinese character meaning water which is decimal 27750 I believe. Do I use wprintf to do this and just include wchar.h ? So far I haven't gotten anything to work. Bill
1
2247
bajajv
by: bajajv | last post by:
Hello, I am trying to implement the CString class. I can implement the functions using the standard namespace string class, but not sure whether it will support the wide characters or not. Also, please suggest that how can I check for characters of other languages? Can I get characters of other languages by changing the language settings of my machine?
0
7981
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8284
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8392
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8262
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6711
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5437
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3894
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2410
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1245
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.