473,563 Members | 2,668 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Advanced Macros && Preprocessors

Hi all,
I'm developing a small defensive programming toolkit for my own
projects. So, here are my questions.

1) Is it possible to move from something like this: SAFECALL(foo(); ) to
__safecall foo();

2) I need to auto-add code to every method of particular class
safeclass MyClass
{
public:
void foo();
}

void MyClass::foo() {}

will modify the foo implementation - add some lines of code on the end
of the method

3) even more advanced stuff, is it possible to modify the preprocessor
(or add my own preprocessor)? I need to parse something like this.
__precheck minutes >= 0 && minutes < 60 #Checking minutes variable for
valid time information
void foo(int minutes){}
__postcheck minutes % 10 == 0 #Checking if minutes have been rounded to
10 minutes intervals
I need also the text behind #

Apr 28 '06 #1
9 4685
Let_Me_Be opined:
Hi all,
I'm developing a small defensive programming toolkit for my own
projects. So, here are my questions.

1) Is it possible to move from something like this: SAFECALL(foo(); )
to __safecall foo();

2) I need to auto-add code to every method of particular class
safeclass MyClass
{
public:
void foo();
}

void MyClass::foo() {}
Are you sure you don't want comp.lang.c++?

will modify the foo implementation - add some lines of code on the
end of the method

3) even more advanced stuff, is it possible to modify the
preprocessor (or add my own preprocessor)? I need to parse something
like this. __precheck minutes >= 0 && minutes < 60 #Checking minutes
variable for valid time information
void foo(int minutes){}
__postcheck minutes % 10 == 0 #Checking if minutes have been rounded
to 10 minutes intervals
I need also the text behind #


--
A father doesn't destroy his children.
-- Lt. Carolyn Palamas, "Who Mourns for Adonais?",
stardate 3468.1.

<http://clc-wiki.net/wiki/Introduction_to _comp.lang.c>

Apr 28 '06 #2
> Are you sure you don't want comp.lang.c++?
Nope, this was just an example, my toolkit should work in both c/c++.

Apr 28 '06 #3
Let_Me_Be wrote:
Hi all,
I'm developing a small defensive programming toolkit for my own
projects. So, here are my questions.

1) Is it possible to move from something like this: SAFECALL(foo(); ) to
__safecall foo();

2) I need to auto-add code to every method of particular class
safeclass MyClass
{
public:
void foo();
}

void MyClass::foo() {}

Wrong group, if you look carefully, you will spot the absence of "++" at
the end of this group's name.

--
Ian Collins.
Apr 28 '06 #4
Let_Me_Be opined:
Are you sure you don't want comp.lang.c++?

Nope, this was just an example, my toolkit should work in both c/c++.


Presumably then, you posted the same question to comp.lang.c++, with an
example in C?

In c.l.c you can only get the C perspective. Whether that's going to be
of any use in C++ is not something to be found (or discussed) here.

Also, do not snip attribution lines (the ones who tell us who said
what), and leave enough context so that your post can be grasped in
isolation. The above worked only because I remembered it was me, and
what I replied to. Read the link in my sig.

--
In Pocatello, Idaho, a law passed in 1912 provided that "The carrying
of concealed weapons is forbidden, unless same are exhibited to public
view."

<http://clc-wiki.net/wiki/Introduction_to _comp.lang.c>

Apr 28 '06 #5
Let_Me_Be wrote:
Are you sure you don't want comp.lang.c++?
Nope, this was just an example, my toolkit should work in both c/c++.


Speaking for myself, I found the examples did not cast
much light on your intentions. What are you trying to do?

The first question was
1) Is it possible to move from something like this: SAFECALL(foo(); )
to
__safecall foo();
.... and it's not at all clear how "like" the actual "something"
would be, nor what sort of "motion" you desire. The second was
2) I need to auto-add code to every method of particular class


.... and I'm unable to imagine how this could have any "image" in
C. All C functions (taking "function" as a translation of "method")
have the same status, as it were: they do not belong to any larger
groupings like "class" or "package," so I can see no way to decide
which functions require manipulation and which should be left alone.
This part of your toolkit needs more explanation -- or, as Vladimir
suggests, you need to take your question elsewhere.

The third example (see up-thread) looks like gibberish. You're
evidently trying to introduce some sort of assertion or error-check,
but you're doing so with a syntax that doesn't look anything at all
like C. Again, either your question needs elaboration or it needs
relocation.

One of the most valuable skills a programmer can hone is the
ability to ask good questions, questions that provide the necessary
information and state clearly what is wanted. You'll forgive me,
I hope, my opinion that you need practice in this skill.

--
Eric Sosman
es*****@acm-dot-org.invalid
Apr 28 '06 #6
> The first question was
> 1) Is it possible to move from something like this: SAFECALL(foo(); )
> to
> __safecall foo();
... and it's not at all clear how "like" the actual "something"
would be, nor what sort of "motion" you desire. The second was


Currently i'm using SAFECALL macro, the syntax is SAFECALL(someth ing),
well, it does work, but much nicer would be __safecall something.
> 2) I need to auto-add code to every method of particular class


... and I'm unable to imagine how this could have any "image" in
C. All C functions (taking "function" as a translation of "method")
have the same status, as it were: they do not belong to any larger
groupings like "class" or "package," so I can see no way to decide
which functions require manipulation and which should be left alone.
This part of your toolkit needs more explanation -- or, as Vladimir
suggests, you need to take your question elsewhere.


Ok, i will try to talk about this in the c++ group.
The third example (see up-thread) looks like gibberish. You're
evidently trying to introduce some sort of assertion or error-check,
but you're doing so with a syntax that doesn't look anything at all
like C. Again, either your question needs elaboration or it needs
relocation.
Problem - visualy divide main code and assertions. I'm acctualy trying
to implement functionality similar to Eiffel.

The syntax doesn't look like C because it isn't C :) Well, that's why
this thread is called Advanced Macros && Preprocessors. The syntax
actualy should look something like this MACRO-HEADER BOOLEAN-EXP
COMMENT (the comment should appear in the error message), or even
better
_start of check block
exp comment
exp comment
_end of check block

Idealy the block should appear after the function header, before the
main code.
One of the most valuable skills a programmer can hone is the
ability to ask good questions, questions that provide the necessary
information and state clearly what is wanted. You'll forgive me,
I hope, my opinion that you need practice in this skill.

--
Eric Sosman
es*****@acm-dot-org.invalid


Apr 28 '06 #7


Let_Me_Be wrote On 04/28/06 09:21,:
The first question was
> 1) Is it possible to move from something like this: SAFECALL(foo(); )
> to
> __safecall foo();
... and it's not at all clear how "like" the actual "something"
would be, nor what sort of "motion" you desire. The second was

Currently i'm using SAFECALL macro, the syntax is SAFECALL(someth ing),
well, it does work, but much nicer would be __safecall something.


Whether you can do this depends on what SAFECALL expands
to. If SAFECALL(x) produces bunch_of_stuff x, then you can
simply define a __safecall macro producing bunch_of_stuff.
If SAFECALL(x) does something more complicated, it cannot be
replaced by an object-like __safecall macro whose expansion
does not itself involve x.

By the way, using two underscores at the start of the
macro name is begging for trouble. Such names "are always
reserved for any use" (7.1.3/1), which means "if you use
them in your program and something goes wrong, it's your
fault and no one else's."
The syntax doesn't look like C because it isn't C :) [...]


So why ask about it in a C forum? Wouldn't alt.woodworking
be equally appropriate?

--
Er*********@sun .com

Apr 28 '06 #8
"Let_Me_Be" <Ha************ @gmail.com> writes:
1) Is it possible to move from something like this: SAFECALL(foo(); ) to
__safecall foo();
This macro will make that literal substitution, although I can't
see how it's useful:
#define SAFECALL(arg) __safecall arg

[...C++ question omitted...]
3) even more advanced stuff, is it possible to modify the preprocessor
(or add my own preprocessor)? I need to parse something like
this. [...]


You can always write your own preprocessor to translate whatever
you like into C. If you use a "make" or similarly powerful build
system, it's not any hard to build such a project than it is to
build an ordinary C project.
--
"C has its problems, but a language designed from scratch would have some too,
and we know C's problems."
--Bjarne Stroustrup
Apr 28 '06 #9
Let_Me_Be wrote:
The first question was
> 1) Is it possible to move from something like this: SAFECALL(foo(); )
> to
> __safecall foo();


... and it's not at all clear how "like" the actual "something"
would be, nor what sort of "motion" you desire. The second was

Currently i'm using SAFECALL macro, the syntax is SAFECALL(someth ing),
well, it does work, but much nicer would be __safecall something.


which doesn't address the issue raised above. "It works" is not a
sufficient description.

One of the options you mentioned earlier is to write your own
preprocessor. If you do that, you can use any syntax you like, but if
you need full C and C++ parsing, the job will be much bigger.
> 2) I need to auto-add code to every method of particular class


I guess you need to write your own. There are probably tools available
to help parse your target language.
--
Thad
Apr 29 '06 #10

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

Similar topics

4
2667
by: josef angermeier | last post by:
i wrote a display driver for a lcd segment display which doesnt recognize ascii character so that each character of an output string needs to be converted byte by byte by looking in a const character table. in short, when calling my output function display.output("hallo") i dont want to call the output function at runtime with the ascii...
7
2101
by: Santa Claus | last post by:
I have the following problem: I would like for a piece of code to be compiled only if a certain macro has been defined AND has some specific value. Let me illustrate: #ifdef SYMBOL f() ; #endif will compile the f() line whenever SYMBOL is defined. Thus, if I have
5
4143
by: sathya_me | last post by:
friends, Please go through the following code which I have downloaded from Bob Stout (Snippets): #include <stdio.h>
1
1499
by: Michael Blackney | last post by:
I've been looking into cascaded macros and I can't seem to find if what I'm doing is portable. I want to do something like: #define THREE_ONES 1,1,1 #define ONE_TWO_THREE 1,2,3 #define JOIN_LISTS(a,b) JOIN_LISTS_PROCESSED(a,b) #define JOIN_LISTS_PROCESSED(a1,b1,c1,a2,b2,c2) a1+a2,b1+b2,c1+c2 so that the statement:
1
400
by: Let_Me_Be | last post by:
Hi all, I'm developing a small defensive programming toolkit for my own projects. So, here are my questions. 1) Is it possible to move from something like this: SAFECALL(foo();) to __safecall foo(); 2) I need to auto-add code to every method of particular class safeclass MyClass {
0
6723
by: Vijay | last post by:
Prep Courses for International Certifications, CSTE & CSQA & ISEB & ISTQB &Business Analyst & SOA Certifications in HYDERABAD. After receiving overwhelming response to our last 50+ batches, SPECTRAMIND SOLUTIONS now announces a new batch of Prep Courses for CSQA & CSTE& ISEB & ISTQB & Business Analyst & SOA so as to prepare you...
4
4390
by: Suzette | last post by:
I have an excel file that automatically updates when opened, pulling information from an Access database into into various pivot tables. I created a macro in Access to perform various necessary functions with the data. I want to be able to open an Access form that I created, and then hit a button that will run the macros and that will open...
0
3186
by: Taxman | last post by:
Windows XP, MS Office Excel 2003 If the tasks, I’m trying accomplish have been addressed previously (separately or in combination). Please, provide the links or keyword search to find them. I’ve been searching for code for each part of the task separately and trying to piece together multiple macros, that do something similar, to what I’m...
45
1967
by: mdh | last post by:
Hi All, The section is titled Variable-length Argument lists. May I ask a question about the use of "macros". To quote K&R. "The standard header <stdarg.hcontains a set of macro definitions that define how to step through an argument list...... The type va_list is used to declare a variable...in minprintf..ap .......The macro va_start...
0
7664
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...
0
7583
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...
0
7885
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. ...
0
8106
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...
1
7638
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...
0
7948
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...
0
6250
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
2082
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
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.