473,670 Members | 2,521 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to prevent macro expansion in C/C++

I am writing codes in windows and Unicode. The windows header file
defines CreateFont into CreateFontW. I am using a class which has a
function CreateFile. So when compiling, I got error that the
CreateFontW is not a member of the class.

What should I do?

Thanks for your help!
Jun 27 '08 #1
4 3693
On 12 Apr., 22:47, 3mwn8tbfrd19... @mail.htl22.at wrote:
I am writing codes in windows and Unicode. The windows header file
defines CreateFont into CreateFontW. I am using a class which has a
function CreateFile. So when compiling, I got error that the
CreateFontW is not a member of the class.

What should I do?

Thanks for your help!
This is one of the reasons that I prefer to stay away from Microsoft
naming conventions. If I were you, I believe that I would simply
include windows.h in your headerfile. It is a hack, but the
alternative would be to change your naming convention and that
probably is to late.

/Peter

PS: I believe you meant CreateFont where you wrote CreateFile or vice
versa.
Jun 27 '08 #2
On 4ÔÂ13ÈÕ, ÉÏÎç4ʱ47·Ö, 3mwn8tbfrd19... @mail.htl22.at wrote:
I am writing codes in windows and Unicode. The windows header file
defines CreateFont into CreateFontW. I am using a class which has a
function CreateFile. So when compiling, I got error that the
CreateFontW is not a member of the class.

What should I do?

Thanks for your help!
#undef CreateFont

before you use it.
Jun 27 '08 #3
* 3m************* @mail.htl22.at:
I am writing codes in windows and Unicode. The windows header file
defines CreateFont into CreateFontW. I am using a class which has a
function CreateFile. So when compiling, I got error that the
CreateFontW is not a member of the class.

What should I do?
Name the function createFile, and for your own functions, don't use leading
uppercase names.

Others will no doubt give you the same advice about #define and #undef as you
got earlier in another group.

And just as then, that advice is ungood but may sound brilliant to idiot.
Cheers, & hth.,

- Alf
Jun 27 '08 #4
On 12 avr, 23:58, "Alf P. Steinbach" <al...@start.no wrote:
* 3mwn8tbfrd19... @mail.htl22.at:
I am writing codes in windows and Unicode. The windows header file
defines CreateFont into CreateFontW. I am using a class which has a
function CreateFile. So when compiling, I got error that the
CreateFontW is not a member of the class.
What should I do?
Name the function createFile, and for your own functions,
don't use leading uppercase names.
I agree, but what about class names? (Or what about the case
where the local coding convention requires upper case names for
functions. It's a convention that I don't like, but it seems to
be fairly frequent.)

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 27 '08 #5

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

Similar topics

25
3234
by: Andrew Dalke | last post by:
Here's a proposed Q&A for the FAQ based on a couple recent threads. Appropriate comments appreciated X.Y: Why doesn't Python have macros like in Lisp or Scheme? Before answering that, a clarification on what 'macro' means. A Lisp macro is a way of modifying code when that code is first defined. It can rearrange the structure of the code, and add and remove parts of it. Unlike C's #define macro language, Lisp macros understand the...
699
33879
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro capabilities, unfortunately. I'd like to know if it may be possible to add a powerful macro system to Python, while keeping its amazing syntax, and if it could be possible to add Pythonistic syntax to Lisp or Scheme, while keeping all of the...
3
2624
by: John | last post by:
Please, consider this macro: #define mymacro(arg1, arg2) arg1 and arg2 Then it is used: mymacro(boys, girls) How is its expansion?
10
2420
by: Karim Thapa | last post by:
Why following macro does not work? #define removebrace(x) x void Foo(int a, int b, char *txt, int d, int e); main() {
5
2000
by: Patrick Kowalzick | last post by:
Hi all, Is this valid? I do not find the case in the standard: void foo( int ) {} #define FOO foo int main() {
4
3686
by: ImOk | last post by:
I come from the Visual Foxpro world, which is one reason I love PHP. VFP is a scripting type language with macro substitution abilities similar to PHP. Besides the regular expansion I can do crazy things (VFP uses & instead of $): x="sales" sales="1000" salestax="8.25"
2
2202
by: talkaboutquality | last post by:
Need to define a macro as, say, #ifdef NEED_FUNCTION foo(x) #else #endif
5
6290
by: Francois Grieu | last post by:
One of the C compiler that I use <OT>(Keil's CX51)</OTbarks at #define a(b) b int main(void){return a( #if 0 #endif 0);} More generally, this compiler seems confused by any preprocessing directive in the middle of macro arguments, which comes handy e.g. to
16
2766
by: mdh | last post by:
I have asked a few questions about Macros...and think what I have been missing ...and which all who have replied clearly understand...is that this is a Pre-processor action. Hopefully the above is true. So, could someone look at this code, and help me understand why I get this error. #include <stdio.h>
6
6969
by: Bing | last post by:
Hi folks, Is there a way to define a macro that may contain #include directive in its body. If I just put the "#include", it gives error C2162: "expected macro formal parameter" since here I am not using # to concatenate strings. If I use "\# include", then I receive the following two errors: error C2017: illegal escape sequence error C2121: '#' : invalid character : possibly the result of a macro
0
8466
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
8384
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8896
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
8810
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
8659
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
4387
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2798
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
2
2035
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1790
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.