473,652 Members | 3,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about a preprocessor operation


Hi to all,

There is my question, Let's say I got a fonction which takes a numeric
argument long enough so that there has to be spaces in it to represent
it correctly. (Ex. 0xf63a002c5ff03 38ec becoming -0xf63a 002c 5ff0
338ec) is there a way to tell the preprocessor to make:

fct(0xf63a 002c 5ff0 338ec) into === fct(0xf63a) f(002c)
(5ff0) (338ec) (exactly as this without the "0x" before the three
lastest forms.

Thanks for your anwsers,
Ludovic

Jan 26 '07 #1
6 1612
lu******@techem ail.com writes:
is there a way to tell the preprocessor to make:

fct(0xf63a 002c 5ff0 338ec) into === fct(0xf63a) f(002c)
(5ff0) (338ec) (exactly as this without the "0x" before the three
lastest forms.
No.
--
"Some programming practices beg for errors;
this one is like calling an 800 number
and having errors delivered to your door."
--Steve McConnell
Jan 26 '07 #2


On Jan 26, 10:28 pm, ludov...@techem ail.com wrote:
Hi to all,

There is my question, Let's say I got a fonction which takes a numeric
argument long enough so that there has to be spaces in it to represent
it correctly. (Ex. 0xf63a002c5ff03 38ec becoming -0xf63a 002c 5ff0
338ec) is there a way to tell the preprocessor to make:

fct(0xf63a 002c 5ff0 338ec) into === fct(0xf63a) f(002c)
(5ff0) (338ec) (exactly as this without the "0x" before the three
lastest forms.
I'm not sure, but I think you could partially achieve your objective
with the ## preprocessor operator, but it's rather tricky to use.

If can at all modify the function, I suggest making it recieve the
value in it's string form and convert it within the function. This way,
you can include spaces and whatnot, and prune them out yourself, before
passing the string to the conversion function.

Also the C preprocessor uses uintmax_t type, so _very_ large values,
such as your example above, will be rejected. You'll need to use a
bignum library to manipulate such integers.

>
Thanks for your anwsers,

Ludovic
Jan 26 '07 #3
<lu******@teche mail.comwrote in message
news:11******** **************@ v33g2000cwv.goo glegroups.com.. .
>
There is my question, Let's say I got a fonction which takes a numeric
argument long enough so that there has to be spaces in it to represent
it correctly. (Ex. 0xf63a002c5ff03 38ec becoming -0xf63a 002c 5ff0
338ec) is there a way to tell the preprocessor to make:

fct(0xf63a 002c 5ff0 338ec) into === fct(0xf63a) f(002c)
(5ff0) (338ec) (exactly as this without the "0x" before the three
lastest forms.
I examined Ben Pfaff's reply. Let me give you more perspective.

There are a LOT of things that the C preprocessor won't do. Here are two
examples from microcontroller work:

#1: It is sometimes desirable to calculate a numerator and denominator so
that a given real number can be approximated by a single integer
multipication followed by a single integer division. For an inexpensive
microcontroller , it might be desirable to put into the source code a real
number (3.141592654, for example) and have this used in the code as the
numerator and denominator of the best rational approximation with numerator
and denominator not exceeding 255. (This approximation is 245/78, by the
way, and can be found by a continued fraction algorithm.) The C
preprocessor can't make the mapping from (3.141592654, 255, 255) to
(245,78).

#2: Software timers are often grouped together in microcontroller work for
efficiency (a timer as I'm using it here is a byte which is periodically
decremented, but not below zero). The preprocessor can't "collect and
combine" timer definitions.

There are a lot of approaches to "escape from" the C preprocessor. People
often use scripting languages or generalize the build process to include
source code which is "decorated" with constructs which are filled-in by
another tool which can make sophisticated mappings beyond the capabilities
of the 'C' preprocessor.

You are not the first to notice that the C preprocessor is simplistic.

People usually write their own tools and introduce another phase or two to
compilation.

--
David T. Ashley (dt*@e3ft.com)
http://www.e3ft.com (Consulting Home Page)
http://www.dtashley.com (Personal Home Page)
http://gpl.e3ft.com (GPL Publications and Projects)
Jan 26 '07 #4
David T. Ashley wrote:
<lu******@teche mail.comwrote in message
news:11******** **************@ v33g2000cwv.goo glegroups.com.. .

There is my question, Let's say I got a fonction which takes a numeric
argument long enough so that there has to be spaces in it to represent
it correctly. (Ex. 0xf63a002c5ff03 38ec becoming -0xf63a 002c 5ff0
338ec) is there a way to tell the preprocessor to make:

fct(0xf63a 002c 5ff0 338ec) into === fct(0xf63a) f(002c)
(5ff0) (338ec) (exactly as this without the "0x" before the three
lastest forms.

I examined Ben Pfaff's reply. Let me give you more perspective.

There are a LOT of things that the C preprocessor won't do. Here are two
examples from microcontroller work:
<snip good examples>
There are a lot of approaches to "escape from" the C preprocessor. People
often use scripting languages or generalize the build process to include
source code which is "decorated" with constructs which are filled-in by
another tool which can make sophisticated mappings beyond the capabilities
of the 'C' preprocessor.
Probably the most common such tool is the m4 generic macro processor,
as it's quite standard and available in a large variety of systems.

Jan 26 '07 #5
"David T. Ashley" wrote:
>
.... snip ...
>
There are a LOT of things that the C preprocessor won't do. Here
are two examples from microcontroller work:

#1: It is sometimes desirable to calculate a numerator and
denominator so that a given real number can be approximated by a
single integer multipication followed by a single integer division.
For an inexpensive microcontroller , it might be desirable to put
into the source code a real number (3.141592654, for example) and
have this used in the code as the numerator and denominator of the
best rational approximation with numerator and denominator not
exceeding 255. (This approximation is 245/78, by the way, and can
be found by a continued fraction algorithm.) The C preprocessor
can't make the mapping from (3.141592654, 255, 255) to (245,78).
No, but you can use:

#define PI 245 / 78
or, better:
#define PI 355 / 113

if you can use values larger than 255. That gives you about 3.5
more significant digits. The parentheses are deliberatly omitted,
so you can get the integer accuracy by using it as:

x = 100 * PI;

With parentheses, you might as well use the Iowa legislature
defined value of 3.

--
Some informative links:
<http://www.catb.org/~esr/faqs/smart-questions.html>
<http://www.caliburn.nl/topposting.html >
<http://www.netmeister. org/news/learn2quote.htm l>
<http://cfaj.freeshell. org/google/ (taming google)
<http://members.fortune city.com/nnqweb/ (newusers)
Jan 26 '07 #6


On Jan 26, 2:34 pm, CBFalconer <cbfalco...@yah oo.comwrote:
[...]
With parentheses, you might as well use the Iowa legislature
defined value of 3.
http://www.snopes.com/religion/pi.htm

Regards,

-=Dave

Jan 26 '07 #7

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

Similar topics

8
1432
by: valued customer | last post by:
Is there a way in python to indicate that you want your "base level of indentation" to be four spaces instead of zero? As far as I know now, the only way is by introducing some sort of language statement, for example: if (1): ### begin python script foo = 1
1
1769
by: Dan W. | last post by:
I've been acting as messenger the past few days between the BOOST and Digital Mars peoples, and they can't seem to come to an agreement about the semantics of using ## vs. juxtaposition. The problem arose when I was trying to compile a boost example program with the DM compiler, and the name of a file which was put together by a set of macros, ended up as, ....\...\list10 .cpp vs. ....\...\list10.cpp
21
4063
by: Jon Slaughter | last post by:
I have a class that is basicaly duplicated throughout several files with only members names changing according to the class name yet with virtually the exact same coding going on. e.g. class A { std::vector<B*> Bs; public:
9
6572
by: ccwork | last post by:
Hi all, We can define some magic number with #define: #define OPERATION_1 0x00000001 #define OPERATION_2 0x00000002 #define OPERATION_3 0x00000003 .... We can also do that with enum: enum OPERATION
4
1465
by: ethan | last post by:
Hi All, I'd like ask some question about macro. If I define a variable set, such as {5, 2, 10} or {1,3}. #define X {5,2,10} 1) Is it possible to write a macro to get the number of items within X? 2) Is it possible to get the nth item within X?
2
6634
by: Paolo | last post by:
I imported a VC++6.0 project into VC++7.1. The conversion operation makes a mess with Preprocessor Definitions, adding a "$(NoInherit)" for each file. For example: I had a DLL project in VC++6.0 where the definitions were: _UNICODE,_DEBUG,_WIN32_DCOM,WIN32,_WINDOWS,_WINDLL,_AFXDLL,_USRDLL In VC++7.1, these are the preprocessor definitions of the project (right-click the project in Solution Explorer and choose Properties -> C++ ->...
6
2031
by: AzizMandar | last post by:
There is probably a better way to do this and if so I'm just as happy to see that way. I have a program where I have factories that each create various objects abstracted from a base class. The Factories all have a base class as well for the objects to point back to. So I have
6
185
by: news.inode.at | last post by:
Sorry for this stupid question, but i am lost. If i write an stringlib with += overload operators (no i do not, but my thing is much more complicated) , and i have to precalculate the strlen() -- as seen in the example here How do i solve this ? struct myStr { private: unsigned len;
5
1137
by: arjor | last post by:
hey guys i was wondering what's the difference between the following commands: #ifndef #if !defined looks to be the same or is it ?
0
8279
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
8811
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...
1
8467
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8589
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...
1
6160
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2703
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
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1591
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.