473,399 Members | 3,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

preprocessor and character literal ('#letter')

Hi,

I have trouble defining a macro - see the following code:

#define LETTER_STRAIGHT(let) let = L'#let'

enum Letter {
LETTER_STRAIGHT(A),
LETTER_STRAIGHT(B),
LETTER_STRAIGHT(C),
};

I want it to expand to this:

enum Letter {
A = L'A',
B = L'B',
C = L'C',
};

However looking at the preprocessing output, it expands to this:

enum Letter {
A = L'#let',
B = L'#let',
C = L'#let',
};

How do I achieve the expansion in the way I want?

Thanks, Boris
Nov 1 '08 #1
6 4206
On Nov 1, 1:00*am, Boris Dušek <boris.du...@gmail.comwrote:
#define LETTER_STRAIGHT(let) let = L'#let'
<snip>
>
enum Letter {
* * A = L'#let',
* * B = L'#let',
* * C = L'#let',

};
You could try

#define LETTER_STRAIGHT(let) let = L#let[0]

which should create
enum Letter {
A = L"A"[0],
B = L"B"[0],
C = L"C"[0],

};
which should be functionally equivalent. You can't create a single
char with preprocessor macros - it's always a string. You can then use
the first char of that string, iirc.
Nov 1 '08 #2
On Nov 1, 9:32*am, "dasca...@gmail.com" <dasca...@gmail.comwrote:
On Nov 1, 1:00*am, Boris Dušek <boris.du...@gmail.comwrote:
#define LETTER_STRAIGHT(let) let = L'#let'
<snip>
enum Letter {
* * A = L'#let',
* * B = L'#let',
* * C = L'#let',
};
You could try
#define LETTER_STRAIGHT(let) let = L#let[0]
which should create
enum Letter {
* * A = L"A"[0],
* * B = L"B"[0],
* * C = L"C"[0],
};
which should be functionally equivalent. You can't create a
single char with preprocessor macros - it's always a string.
You can then use the first char of that string, iirc.
You can, but the result of a dereferce operator is never a
constant expression, even if you're dereferencing a string
literal, so it can't be used as the initializer of an enum
constant (or an array dimension, or a template argument).

There are a number of different work-arounds possible, but
without knowing what problem he's trying to solve, it's
difficult to recommand any. Off hand, I don't see what the
problem is in writing:

enum Letter
{
A = L'A',
B = L'B',
C = L'C'
} ;

directly.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Nov 1 '08 #3
James Kanze wrote:
Off hand, I don't see what the
problem is in writing:

enum Letter
{
A = L'A',
B = L'B',
C = L'C'
} ;

directly.
Maybe he is trying to abstract the precise character type (L) away?
Nov 1 '08 #4
#define LETTER_STRAIGHT(let) let = L#let[0]
which should create
enum Letter {
* * A = L"A"[0],
* * B = L"B"[0],
* * C = L"C"[0],
};
which should be functionally equivalent. You can't create a
single char with preprocessor macros - it's always a string.
You can then use the first char of that string, iirc.

You can, but the result of a dereferce operator is never a
constant expression
Right, the compiler complains about that.
difficult to recommand any. *Off hand, I don't see what the
problem is in writing:

* * enum Letter
* * {
* * * * A = L'A',
* * * * B = L'B',
* * * * C = L'C'
* * } ;

directly.
I had to write something like 100 enum values, so having a macro that
saves typing (if you copy/paste the line 100 times and then just
change one letter) and that helps avoiding a mistake that would result
from forgetting to change the right-hand side when I changed the left-
hand side is a plus. But I used vim to easily change it to the
explicit form, now it of course works.

What I am doing is that I want to include Unicode codepoints for all
letters in Czech alphabet (i.e. asides from English alphabet, 15 more
like ì¹èø¾ýáíé) into the enum, and then define uppercasing,
lowercasing and asciifying (é -e) tables using these enum values
rather than the codepoints directly. I want to avoid relying on cs_CZ
or Czech locale, since i.e. Mac OS X's support for locale is basically
non-existent (i.e. even std::locale("") throws std::runtime_error; the
same for std::locale("cs_CZ") or any other even if it is present in /
usr/share/locale). So I have to have my own conversion tables. And
btw., the goal of all of this is to write an app that tries its best
to deasciify an asciified text.

Thanks to both of you for your ideas,
Boris
Nov 1 '08 #5
On Nov 1, 11:09*am, Boris Dušek <boris.du...@gmail.comwrote:
#define LETTER_STRAIGHT(let) let = L#let[0]
which should create
enum Letter {
* * A = L"A"[0],
* * B = L"B"[0],
* * C = L"C"[0],
};
which should be functionally equivalent. You can't create
a single char with preprocessor macros - it's always a
string. You can then use the first char of that string,
iirc.
You can, but the result of a dereferce operator is never a
constant expression
Right, the compiler complains about that.
difficult to recommand any. *Off hand, I don't see what the
problem is in writing:
* * enum Letter
* * {
* * * * A = L'A',
* * * * B = L'B',
* * * * C = L'C'
* * } ;
directly.
I had to write something like 100 enum values, so having a
macro that saves typing (if you copy/paste the line 100 times
and then just change one letter) and that helps avoiding a
mistake that would result from forgetting to change the
right-hand side when I changed the left- hand side is a plus.
But I used vim to easily change it to the explicit form, now
it of course works.
Exactly. Any decent editor will be able to handle this.
What I am doing is that I want to include Unicode codepoints
for all letters in Czech alphabet (i.e. asides from English
alphabet, 15 more like ì¹èø¾ýáíé) into the enum, and then
define uppercasing, lowercasing and asciifying (é -e) tables
using these enum values rather than the codepoints directly.
That actually sounds like a pretty reasonable thing to do. I'd
write a simple AWK script, however, to generate the whole thing
from a simple two column list: the wide character and its ascii
equivalent.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Nov 2 '08 #6
On 1 ноÑб, 03:00, Boris DuÅ¡ek <boris.du...@gmail.comwrote:
Hi,

I have trouble defining a macro - see the following code:

#define LETTER_STRAIGHT(let) let = L'#let'

enum Letter {
Â* Â* LETTER_STRAIGHT(A),
Â* Â* LETTER_STRAIGHT(B),
Â* Â* LETTER_STRAIGHT(C),

};

I want it to expand to this:

enum Letter {
Â* Â* A = L'A',
Â* Â* B = L'B',
Â* Â* C = L'C',

};

However looking at the preprocessing output, it expands to this:

enum Letter {
Â* Â* A = L'#let',
Â* Â* B = L'#let',
Â* Â* C = L'#let',

};

How do I achieve the expansion in the way I want?

Thanks, Boris
There is a Microsoft specific solution - charizing operator:
#define LETTER_STRAIGHT(let) let = L#@let

Thanks, Alexey.
Nov 2 '08 #7

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

Similar topics

1
by: Axier | last post by:
I cannot get the swedish character set on images. What can be wrong? I would very much appreciate help. regards, axier I can supply some code here and a link:...
38
by: Haines Brown | last post by:
I'm having trouble finding the character entity for the French abbreviation for "number" (capital N followed by a small supercript o, period). My references are not listing it. Where would I...
9
by: Walter Roberson | last post by:
I have run into a peculiarity with SGI's C compiler (7.3.1.2m). I have been reading carefully over the ANSI X3.159-1989 specification, but I cannot seem to find a justification for the behaviour....
5
by: .rhavin grobert | last post by:
i read that the preproc will parse macros inside a string if they are prefixed with a sharp. so i did.... ________________________- #define MAJORRELEASE 0 #define PATCHLEVEL 7 #ifdef _DEBUG...
31
by: Sam of California | last post by:
Is it accurate to say that "the preprocessor is just a pass in the parsing of the source file"? I responded to that comment by saying that the preprocessor is not just a pass. It processes...
5
by: John Speth | last post by:
Hi Group- I want to use the C preprocessor to generate expanded text as a text processor for software test script generation. The preprocessor output will never be compiled. I need to insert...
9
by: jraul | last post by:
1) Am I correct that C++ does not have a defined character set? In particular, a platform might not use the ASCII character set? 2) C++ supports wchar_t types. But again, this has no defined...
3
KevinADC
by: KevinADC | last post by:
Purpose The purpose of this article is to discuss the difference between characters inside a character class and outside a character class and some special characters inside a character class....
4
by: zaimoni | last post by:
I've already calculated that the following are valid and should not error, as both just end up with the character literal 'A' being their control expression. The unspecified value of the char*...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.