C preprocessor

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2005
Posts: 4
Reputation: iamlearning is an unknown quantity at this point 
Solved Threads: 0
iamlearning iamlearning is offline Offline
Newbie Poster

C preprocessor

 
0
  #1
Dec 29th, 2005
I would like to create a macro to convert a variable string into the UNICODE (16 bits).
Example:
#define UNICODE ("xyz") - It will return 0,'x',0,'y',0, z at compilation time.

The size of parameter to the macro can be any length.

Thanks for helping
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,846
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 753
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: C preprocessor

 
0
  #2
Dec 29th, 2005
Something like this?
  1. #include <stdio.h>
  2. #include <wchar.h>
  3.  
  4. #define UNICODE(x) L#x
  5.  
  6. int main ( void )
  7. {
  8. wchar_t *p = UNICODE ( xyz\n );
  9.  
  10. fputws ( p, stdout );
  11.  
  12. return 0;
  13. }
By the way, Unicode is only an encoding, not a storage specification. The actual storage is with multi-byte characters that happen to represent Unicode codes. Technically, you can use Unicode with single byte characters as long as you restrict yourself to the single byte Unicode values.
New members chased away this month: 4
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 4
Reputation: iamlearning is an unknown quantity at this point 
Solved Threads: 0
iamlearning iamlearning is offline Offline
Newbie Poster

Re: C preprocessor

 
0
  #3
Dec 30th, 2005
Originally Posted by Narue
Something like this?
  1. #include <stdio.h>
  2. #include <wchar.h>
  3.  
  4. #define UNICODE(x) L#x
  5.  
  6. int main ( void )
  7. {
  8. wchar_t *p = UNICODE ( xyz\n );
  9.  
  10. fputws ( p, stdout );
  11.  
  12. return 0;
  13. }
By the way, Unicode is only an encoding, not a storage specification. The actual storage is with multi-byte characters that happen to represent Unicode codes. Technically, you can use Unicode with single byte characters as long as you restrict yourself to the single byte Unicode values.
This is for the USB message which require 16-bit Unicode character. We can always do this in the function but I wonder if we can do it in the macro that will have the message at compilation so it will run faster.

Thanks a lot for your post.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,618
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1491
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: C preprocessor

 
0
  #4
Dec 30th, 2005
you can use that macro anywhere you use a string literal. You can't, however, use that macro with a char*
  1. // this will NOT work
  2. char* hello = "Hello World";
  3. wchar_t thello = UNICODE(hello);
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,846
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 753
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: C preprocessor

 
0
  #5
Dec 30th, 2005
Originally Posted by Ancient Dragon
you can use that macro anywhere you use a string literal. You can't, however, use that macro with a char*
  1. // this will NOT work
  2. char* hello = "Hello World";
  3. wchar_t thello = UNICODE(hello);
Your point being? There was never any assumption that the macro would be used with narrow string variables, unless you were reading a few posts that I conveniently missed. Or are you just posting pointless fluff to make yourself look smart when you can't find anything meaningful to add?
New members chased away this month: 4
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,618
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1491
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: C preprocessor

 
0
  #6
Dec 31st, 2005
Originally Posted by Narue
Your point being? There was never any assumption that the macro would be used with narrow string variables, unless you were reading a few posts that I conveniently missed. Or are you just posting pointless fluff to make yourself look smart when you can't find anything meaningful to add?
getting pretty snotty now aren't you or are you suffering from pms today :mrgreen:

you might (or might not) be supprised at the number of people I've see try to do what I mentioned, so its not an unreasonable thing to warn people about.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,052
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: C preprocessor

 
4
  #7
Dec 31st, 2005
Unicode is not an encoding, the actual storage specification is the character encoding. Unicode is more accurately described a coded character set.
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: C preprocessor

 
0
  #8
Dec 31st, 2005
are you suffering from pms today
Isn't that like the eight wonder of the natural world, for us men anyway? He he.

Don't worry Narue the New Year may be more hopeful.

God bless everyone.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,846
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 753
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: C preprocessor

 
0
  #9
Dec 31st, 2005
>getting pretty snotty now aren't you or are you suffering from pms today :mrgreen:
That was pretty sharp-tongued, even for me. I was suffering from arrogant forumgoers trying to show off their brilliance by incorrectly "correcting" me with meaningless crap. But you wouldn't do that...more than once.

>you might (or might not) be supprised
I'm very surprised, actually, since it's immediately obvious what the macro does and that it only works with string literals. Though I shouldn't be surprised, with the rampant idiocy of many programmers. :rolleyes:

>Unicode is not an encoding
From dictionary.com:
encoding: Computer Science. To format (electronic data) according to a standard format.
From unicode.org (emphasis is mine):
Q: What is Unicode?
A: Unicode is the universal character encoding, maintained by the Unicode Consortium. This encoding standard provides the basis for processing, storage and interchange of text data in any language in all modern software and information technology protocols.
Now, it's entirely possible that the Unicode Consortium doesn't know what encoding means, or hired someone to write their FAQ who doesn't know what encoding means, or you're being far too pedantic and making mistakes in the process.

How about we meet halfway and call Unicode a code table? I respect you too much to flame you out of existence.
New members chased away this month: 4
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,052
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: C preprocessor

 
2
  #10
Jan 1st, 2006
I don't think so. What is generally called a character encoding, they call a Character Encoding Scheme. See http://www.unicode.org/glossary/. And their definition of Coded Character Set would characterize Unicode nicely. Their glossary doesn't give a definition of character encoding, probably because they've avoided using the term because it's sometimes used in different ways. I would not call a numbering of a series of characters an encoding.

To say that "Unicode is just an encoding" is misleading, because "character encoding" normally refers to the storage specification, such as UTF-8 or UTF-16BE. This is how the term is usually used, and their FAQ goes against the norm. (I'm basing what I call the 'norm' from looking at the View > 'Character Encoding' menu in Firefox, the 'Encoding' menu in I.E., and just about every link I've looked at in a Google search for 'unicode character encoding'.)
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC