473,386 Members | 1,715 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,386 software developers and data experts.

CPP Multi-Line Macro Expansion Needs

Good day folks.

Let me open with the statement that I am not a C++/C programmer. The environment that I am programming in is ARMbasic, an embedded BASIC targeted toward ARM-based micro-controllers. So why am I posting herein? Well, the ARMbasic environment makes use of a tool borrowed from your folk's environment - CPP. The build details are:

Expand|Select|Wrap|Line Numbers
  1. C:\Program Files\Coridium>cpp --version
  2. cpp (GCC) 3.2.3 (mingw special 20030504-1)
  3. Copyright (C) 2002 Free Software Foundation, Inc.
CPP was added recently to the ARMbasic environment to enable the building of more complex apps, via the leveraging of existing code libraries, as I am sure all of you are aware of in the C++/C environment.

My question is this: Is there a way to get a proprocessor macro to expand to multiple lines of code?

Scenario: I have a function created where the internal Analog to Digital Converter is queried and the integer result is returned. On the target that I am programming (an NXP 2103 micro), the ADC converter is able to run at 4.5 MHZ (or less) - this equates to approx 3us if coded in ASM. If coded in C (by the ARMbasic developer), the read time is ~5us. With my ARMbasic function, due to system overhead, etc., my function is taking 11us. This is acceptable in most cases, but I have a peer that is needing higher throughput.

If I manually code my ADC reads in-line, via 2 POKES, 2 PEEKS and 1 conditional loop per ADC read, I can get the acquisition time down to 8us. The target, in this case of helping my peer out, is to get the code down to <=10us. So, the problem is solvable by manually coding in a bunch of in-line pokes/peeks. However, with the Preprocessor, it seems that I could substitute in-line code vs. the function calls by simply #define-ing a new in-line ADC input routine:

==================================================
CURRENT IMPLEMENTATION
==================================================

Current Function:

Expand|Select|Wrap|Line Numbers
  1. Function AD (channel as integer) as integer
  2.     CALL POKE (AD_ADCR, ((1 << channel) + AD_ENABLE))
  3.     CALL POKE (AD_ADCR, ((1 << channel) + AD_START))
  4.     DO
  5.     UNTIL (PEEK(AD_ADGDR) AND $80000000) // wait for the conversion
  6.     RETURN (PEEK(AD_ADGDR) AND $FFFF)>>6
  7. ENDFUNCTION
Calling Code:

Expand|Select|Wrap|Line Numbers
  1. blah = AD(ch)  // <<<<<  this is 11us with above function
==================================================
DESIRED IMPLEMENTATION
==================================================

Desired Inline Macro:

Expand|Select|Wrap|Line Numbers
  1. #begin ADC_INLINE (channel,variable)
  2.     CALL POKE (AD_ADCR, ((1 << channel) + AD_ENABLE))
  3.     CALL POKE (AD_ADCR, ((1 << channel) + AD_START))
  4.     DO
  5.     UNTIL (PEEK(AD_ADGDR) AND $80000000) // wait for the conversion
  6.     variable = (PEEK(AD_ADGDR) AND $FFFF)>>6
  7. #end
New Calling Code?:

Expand|Select|Wrap|Line Numbers
  1. ADC_INLINE (6, blah)  // <<< this should yield target speed
==================================================

ARMbasic doesn't allow multiple commands on a single line of code - i.e. 1 command per line, period. If I correctly understand the many CPP guidance texts that I have read, I take it that multi-line macro definitions, when 'expanded' will actually concatenate the multi-line definition to a single line, with new-line operators embedded therein - this is my root issue...

Is there a means to easily get CPP to expand a macro definition, with passed argument substitution, to multiple lines, exactly as defined in the Macro Def?

I have searched high and low, and have come up empty handed (actually dirty handed, as I have found a couple of solutions, but those solutions require skill sets that I do not possess).

The most attractive solution is a patch to CPP that has a #begin/#end macro definition construct/directive. It is located here.

A viable alternate solution seems to be located here.

The problem with both of these approaches is that I simply do not possess the tools or skill sets to take this source and compile it for use on a win32 platform...

So, my plea is this: Can someone point me toward either a win32 CPP binary that has the desired construct built-in already, or advise, in a rather detailed fashion (TIA) how one could use GNU CPP, in it's native form, to expand a macro definition to multiple lines, with parameter replacement and without extra syntax being added or definition syntax being altered? Please.

Thanks for taking the time to read my diatribe.

-Tod Wulff
Dec 19 '07 #1
1 3344
mac11
256 100+
==================================================
DESIRED IMPLEMENTATION
==================================================

Desired Inline Macro:

Expand|Select|Wrap|Line Numbers
  1. #begin ADC_INLINE (channel,variable)
  2.     CALL POKE (AD_ADCR, ((1 << channel) + AD_ENABLE))
  3.     CALL POKE (AD_ADCR, ((1 << channel) + AD_START))
  4.     DO
  5.     UNTIL (PEEK(AD_ADGDR) AND $80000000) // wait for the conversion
  6.     variable = (PEEK(AD_ADGDR) AND $FFFF)>>6
  7. #end
New Calling Code?:

Expand|Select|Wrap|Line Numbers
  1. ADC_INLINE (6, blah)  // <<< this should yield target speed
==================================================
I didn't read everything you wrote, but it looks like you want something like this:
Expand|Select|Wrap|Line Numbers
  1.       #define ADC_INLINE ((channel),(variable))   \
  2.           CALL POKE (AD_ADCR, ((1 << (channel)) + AD_ENABLE));  \
  3.           CALL POKE (AD_ADCR, ((1 << (channel)) + AD_START));   \
  4.           DO   \
  5.           UNTIL (PEEK(AD_ADGDR) AND $80000000);  \
  6.           variable = (PEEK(AD_ADGDR) AND $FFFF)>>6; 
  7.  

Basically you use \ to extend your macro to multiple lines. I added semi-colons at the end of the lines, but I'm not sure how the DO / UNTIL part works so you'll probably have to adjust
Dec 19 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

37
by: ajikoe | last post by:
Hello, Is anyone has experiance in running python code to run multi thread parallel in multi processor. Is it possible ? Can python manage which cpu shoud do every thread? Sincerely Yours,...
4
by: Frank Jona | last post by:
Intellisense with C# and a multi-file assembly is not working. With VB.NET it is working. Is there a fix availible? We're using VisualStudio 2003 Regards Frank
12
by: * ProteanThread * | last post by:
but depends upon the clique: ...
0
by: frankenberry | last post by:
I have multi-page tiff files. I need to extract individual frames from the multi-page tiffs and save them as single-page tiffs. 95% of the time I receive multi-page tiffs containing 1 or more black...
6
by: cody | last post by:
What are multi file assemblies good for? What are the advantages of using multiple assemblies (A.DLL+B.DLL) vs. a single multi file assembly (A.DLL+A.NETMODULE)?
6
by: Joe | last post by:
I have 2 multi-list boxes, 1 displays course categories based on a table called CATEGORIES. This table has 2 fields CATEGORY_ID, CATEGORY_NAME The other multi-list box displays courses based on...
4
by: mimmo | last post by:
Hi! I should convert the accented letters of a string in the correspondent letters not accented. But when I compile with -Wall it give me: warning: multi-character character constant Do the...
5
by: Shane Story | last post by:
I can seem to get the dimensions of a frame in a multiframe tiff. After selecting activeframe, the Width/Height is still really much larger than the page's actual dimensions. When I split a...
5
by: bobwansink | last post by:
Hi, I'm relatively new to programming and I would like to create a C++ multi user program. It's for a project for school. This means I will have to write a paper about the theory too. Does anyone...
0
by: Sabri.Pllana | last post by:
We apologize if you receive multiple copies of this call for papers. *********************************************************************** 2008 International Workshop on Multi-Core Computing...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...

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.