473,386 Members | 1,812 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.

__func__ macro emulation


I'm using a preprocessor/compiler (HP aCC) that doesn't support the
__func__ macro (a la gcc: expands to the name of the enclosing
function). I've thought about using an extra preprocessing step, writing
a parser, etc but this seems like way too much work. Has anyone tried
this before? Any suggestions welcome!
--
Posted via http://dbforums.com
Jul 19 '05 #1
3 5488
chasdev <me*********@dbforums.com> wrote in message news:<35****************@dbforums.com>...
I'm using a preprocessor/compiler (HP aCC) that doesn't support the
__func__ macro (a la gcc: expands to the name of the enclosing
function). I've thought about using an extra preprocessing step, writing
a parser, etc but this seems like way too much work. Has anyone tried
this before? Any suggestions welcome!

aCC should use __FUNCTION__.

You may take look on file boost/current_function.hpp from Boost
distribution, it contains macro expanded properly under many
compilers.

/Pavel
Jul 19 '05 #2
chasdev wrote:

I'm using a preprocessor/compiler (HP aCC) that doesn't support the
__func__ macro (a la gcc: expands to the name of the enclosing
function). I've thought about using an extra preprocessing step, writing
a parser, etc but this seems like way too much work. Has anyone tried
this before? Any suggestions welcome!
--
Posted via http://dbforums.com


Maybe you could manually keep track of the current function, i.e:

#include <vector>
#include <string>
#include <iostream>

class FunctionTracer
{
private:
std::vector<std::string> Trace;
int MaxSteps;
public:
FunctionTracer(int);
void EnterFunction(const std::string&);
void LeaveFunction(const std::string&);
void SetMaxSteps(int);
void Reset();
};

FunctionTracer::FunctionTracer(int n) : MaxSteps(n)
{
Trace.clear();
Trace.reserve(MaxSteps);
}

void FunctionTracer::EnterFunction(const std::string& s)
{
if (Trace.size() == MaxSteps)
Trace.clear();
Trace.push-back(s);
}

void FunctionTracer::LeaveFunction(const std::string& s)
{
if (Trace.back() == s) // the function we are leaving will be th
e last one we entered
Trace.pop_back();
else
; // error!
}

void SetMaxSteps(int n)
{std::cout << ft.CurrentFunction();
if (MaxSteps != n)
{
MaxSteps = n;
Trace.reserve(MaxSteps);
}
}

void Reset()
{
Trace.clear();
}

//test it

FunctionTracer ft(10);

void f1()
{
ft.EnterFunction("f1");
std::cout << "in function 1\n";
ft.LeaveFunction("f1");
}
void f2()
{
ft.EnterFunction("f2");
std::cout << "in function2\n";
ft.LeaveFunction("f2");
}

int main()
{
ft.EnterFunction("main");
f1();
std::cout << ft.CurrentFunction();
f2();
std::cout << ft.CurrentFunction();
}

This is untested code, I just wrote as it came...so don't blame me if its
broken and buggy (as it probaly will be!). I hope it helps anyway.
S. Armondi

Jul 19 '05 #3

"Samuele Armondi" <ar*******@yahoo.co.uk> wrote in message
news:3f********@mk-nntp-1.news.uk.worldonline.com...
chasdev wrote:

I'm using a preprocessor/compiler (HP aCC) that doesn't support the
__func__ macro (a la gcc: expands to the name of the enclosing
function). I've thought about using an extra preprocessing step, writing
a parser, etc but this seems like way too much work. Has anyone tried
this before? Any suggestions welcome!
--
Posted via http://dbforums.com
Maybe you could manually keep track of the current function, i.e:

#include <vector>
#include <string>
#include <iostream>

class FunctionTracer
{

<snip> std::cout << ft.CurrentFunction();
}

This is untested code, I just wrote as it came...so don't blame me if its
broken and buggy (as it probaly will be!). I hope it helps anyway.
S. Armondi

Sorry, I forgot to add the CurrentFunction() code... the code should look
like this:

#include <vector>
#include <string>
#include <iostream>

class FunctionTracer
{
private:
std::vector<std::string> Trace;
int MaxSteps;
public:
FunctionTracer(int);
void EnterFunction(const std::string&);
void LeaveFunction(const std::string&);
void SetMaxSteps(int);
void Reset();
const std::string& CurrentFunction();
};

FunctionTracer::FunctionTracer(int n) : MaxSteps(n)
{
Trace.clear();
Trace.reserve(MaxSteps);
}

void FunctionTracer::EnterFunction(const std::string& s)
{
if (Trace.size() == MaxSteps)
Trace.clear();
Trace.push-back(s);
}

void FunctionTracer::LeaveFunction(const std::string& s)
{
if (Trace.back() == s) // the function we are leaving will
be th
e last one we entered
Trace.pop_back();
else
; // error!
}

void SetMaxSteps(int n)
{std::cout << ft.CurrentFunction();
if (MaxSteps != n)
{
MaxSteps = n;
Trace.reserve(MaxSteps);
}
}

void Reset()
{
Trace.clear();
}

const std::string& CurrentFunction()
{
return Trace.back();
}

//test it

FunctionTracer ft(10);

void f1()
{
ft.EnterFunction("f1");
std::cout << "in function 1\n";
ft.LeaveFunction("f1");
}
void f2()
{
ft.EnterFunction("f2");
std::cout << "in function2\n";
ft.LeaveFunction("f2");
}

int main()
{
ft.EnterFunction("main");
f1();
std::cout << ft.CurrentFunction();
f2();
std::cout << ft.CurrentFunction();
}

Jul 19 '05 #4

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

Similar topics

16
by: Chris | last post by:
Is there any way to make the class Z behave the same way as class Y? Chris class Y: value = 42 def __hasattr__(self, name): if name == '__int__': return True def __getattr__(self, name):
0
by: Pam Sheldon | last post by:
I have an app that uses data files. How can get the files over to the emulator so I can debug the app in the emulation mode? Microsoft does not say this is a limitation of the emulator. Pam
3
by: Gilles Cadorel | last post by:
I'd like to add in a HTML page a button, that open a Unix Emulation on a new Windows, when I clik on it. I'm using WRQ Reflection to connect to Unix hosts. The problem is that I don't want the...
18
by: qwweeeit | last post by:
Hi all, when I moved from Windows to Linux I choosed Python as my language of reference and as GUI, Qt (not much investigated up to now). Till now I didn't regret but one thing: Python can't act...
2
by: djinni | last post by:
howdy, Can anyone tell me where the function name string is stored when __func__ is used? I read that it is basically like declaring a static const char, but when I compile the following code,...
9
by: dave_140390 | last post by:
Hi, Is there a clean way to determine at compile-time whether your compiler supports the __func__ feature? I mean, something similar to the following (which tests for the existence of macro...
10
by: Guillaume Dargaud | last post by:
Hello all, Is it the same thing to do those two things: #define WHERE printf("We are in %s", __func__) void Function(void) { WHERE; } And this:
36
by: sh.vipin | last post by:
how to make large macro paste the code as it is Problem Explanation '-- For example in the program below /* a.c - starts here */ #define DECL_VARS() \ unsigned int a0;\ unsigned int a1;\...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
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,...
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
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.