Jump to content
  • Advertisement
Sign in to follow this  
nlbs

overloading macro

This topic is 3611 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've a macro called $_SESSION() and if one argument is passed to it it will invoke the getter method and if two arguments has been passed it will invoke the setter

Share this post


Link to post
Share on other sites
Advertisement
The '$' prefix leads me to believe that you're dealing with PERL, PHP or an SH variant. Since PHP and SH have no macros and PERL 6 macros don't look like that, I'm left to wonder, what are you talking about?

Share this post


Link to post
Share on other sites
no I want to make a $_SESSION() macro which will behave like PHP's $_SESSION and abstract other Complex CGI Librery method Calls

Share this post


Link to post
Share on other sites
In which language?

Going out on a limb and assuming C or C++, it's not possible. First the name cannot start with $, and secondly macros cannot be overloaded.

Share this post


Link to post
Share on other sites
Right. That's not much better, but at least we got something to work with:
function session()
{
$args = func_get_args();
if (count($args) == 1) return get_value($args[0]);
if (count($args) == 2) return set_value($args[0], $args[1]);
assert (false);
}

// Warning: not a superglobal!
$_MY_SESSION = 'session';

Share this post


Link to post
Share on other sites
Man why you are not understanding

#define $_SESSION(k) session::get(k)
#define $_SESSIOn(k, v) session::add(k, v)

but compiler warns that multiple defenition of $_SESSION macro

C++ doesn't forbids macros starting with $

Share this post


Link to post
Share on other sites
Quote:
Original post by nlbs
Man why you are not understanding
Well, it's been five messages already in this thread, and even though I mentioned in the first message that you didn't specify the language you were enquiring about, you've waited until now to mention C++. Why have you not mentioned that earlier, thereby saving me the wasted time of proposing a PHP solution?

Seriously, you're just wasting everyone's time. The reason why you don't get the correct answer is because you suck at asking questions.

Quote:
but compiler warns that multiple defenition of $_SESSION macro

Macros cannot be overloaded. Use a different solution, for instance create a class with an overloaded operator[] returning an object with an impicit conversion (that calls get) and an assignment operator (that calls set).

Quote:
C++ doesn't forbids macros starting with $
It does, '$' is only allowed as a microsoft extension.

Share this post


Link to post
Share on other sites
Sorry as its mainly a C++ forum I thought its not required to say C++ explecitely

ok so if it cant be overloaded how can i make a macro that can accept one argument as well as two argument too.

I am using g++ and I've 4-5 macro's already running well who's name starts with $ sign.

Share this post


Link to post
Share on other sites
Quote:

Man why you are not understanding

Don't be rude to people trying to help you. You're original questions are far too vague; we don't read minds here.

Quote:

but compiler warns that multiple defenition of $_SESSION macro

Because you cannot overload macros. They are part of the preprocessor, and exist for simple, naive textual substitution.

Quote:

ok so if it cant be overloaded how can i make a macro that can accept one argument as well as two argument too.

You can't, the macros have to have different names. You can also use a function (an actual, honest C++ function) which can be overloaded.

Quote:

C++ doesn't forbids macros starting with $...I am using g++ and I've 4-5 macro's already running well who's name starts with $ sign.

Yes it does, '$' is not in the basic source character set. Visual C++ and some other compilers (including GCC) will let you use the character in an identifier as a language extension. If you disable extensions then it should provide you with an error (if it doesn't, the compiler is non-compliant with the C++ standard on that point).

Share this post


Link to post
Share on other sites
ok so if it cant be overloaded how can i make a macro that can accept one argument as well as two arguments too. with teh same name e.g. one optional argument

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!