1. wrapping macros?

Is it possible to wrap a marco from a C/C++ file?
Will i just have to go look at the marco in the source file and re-code it
in Eu or can i just use a c_func or something? Im thinking im goin to have
to re-code those macros in Eu, but i just wanted to be sure before i go
ahead with it.

When i say macro. i mean as so:

// In C
#define MIN(a,b) (((a) < (b)) ? a : b)

Any response is appreciated.

-- 
evil, corruption and bad taste
^[cense]

new topic     » topic index » view message » categorize

2. Re: wrapping macros?

cense wrote:


> Is it possible to wrap a macro from a C/C++ file?

Not directly. They don't really exist; they just tell the pre-processor what
to do. But if you define a function that uses the macro, you can wrap that
function. For example:

// function that wraps the macro
integer min(a,b) { return MIN(a,b) }

-- David Cuny

new topic     » goto parent     » topic index » view message » categorize

3. Re: wrapping macros?

>// function that wraps the macro
>integer min(a,b) { return MIN(a,b) }
>
>-- David Cuny


Though I'd do this (in Euphoria):

function min(atom a,atom b)
  if (a<b) then return a end if
  return b
end function


_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Share information about yourself, create your own public profile at
http://profiles.msn.com.

new topic     » goto parent     » topic index » view message » categorize

4. Re: wrapping macros?

On Fri, 27 Oct 2000, mic _ wrote:
>> >// function that wraps the macro
>> >integer min(a,b) { return MIN(a,b) }
>> >
>> >-- David Cuny
>> 
>> 
>> Though I'd do this (in Euphoria):
>> 
>> function min(atom a,atom b)
>>   if (a<b) then return a end if
>>   return b
>> end function
>> 

The macros i want to use are not as simple as MIN(a, b) they are actually
complex for just a macro, i wonder why they did not use routines instead.
Ah well, ancient socket code is odd, quite odd.

Thanks David.

-- 
evil, corruption and bad taste
^[cense]

new topic     » goto parent     » topic index » view message » categorize

5. Re: wrapping macros?

On Fri, 27 Oct 2000 21:14:10 -0600, cense <cense at MAIL.RU> wrote:

>The macros i want to use are not as simple as MIN(a, b) they are actually
>complex for just a macro, i wonder why they did not use routines instead.
>Ah well, ancient socket code is odd, quite odd.

   cense:

   The are two basic purposes for using MACROS in programming.

   1. A macro is defined at the beginning of a program and given
      a MACRO name.
      Then when ever a programmer invokes that MACRO's name later
      in the program. The code is then inserted directly at that point
      in the programmer's program when EVER the MACRO name is used.
      This is different than calling a function because the a function's
      code is only inserted in the program in ONE place and called from
      other places in the program. Placing the same code in more than
      1 place in a programming in some languages increases speed by
      eliminating the overhead of calling but this also icreases the
      size of the program.

   2. The second kind of MACRO is used as a kind of TEMPLATE.
      The progammer invokes the MACRO's name using it different
      parameters when the compiler see the MACRO name it inserts
      the code at the location where the MACRO name is invoked
      but uses DIFFERENT code depending on what parameters were
      used when the MACRO name was invoked.

   You should now be able to answer the question; can I use a function
   call instead of a MACRO.
   The only thing that is complicated is determining what exactly
   the MACRO is used to accomplish.

  I hopes this clears this up for you.

  Bernie

new topic     » goto parent     » topic index » view message » categorize

6. Re: wrapping macros?

On Sat, 28 Oct 2000, Bernie wrote:
>> On Fri, 27 Oct 2000 21:14:10 -0600, cense <cense at MAIL.RU> wrote:
>> 
>> >The macros i want to use are not as simple as MIN(a, b) they are actually
>> >complex for just a macro, i wonder why they did not use routines instead.
>> >Ah well, ancient socket code is odd, quite odd.
>> 
>>    cense:
>> 
>>    The are two basic purposes for using MACROS in programming.
>> 
>>    1. A macro is defined at the beginning of a program and given
>>       a MACRO name.
>>       Then when ever a programmer invokes that MACRO's name later
>>       in the program. The code is then inserted directly at that point
>>       in the programmer's program when EVER the MACRO name is used.
>>       This is different than calling a function because the a function's
>>       code is only inserted in the program in ONE place and called from
>>       other places in the program. Placing the same code in more than
>>       1 place in a programming in some languages increases speed by
>>       eliminating the overhead of calling but this also icreases the
>>       size of the program.
>> 
>>    2. The second kind of MACRO is used as a kind of TEMPLATE.
>>       The progammer invokes the MACRO's name using it different
>>       parameters when the compiler see the MACRO name it inserts
>>       the code at the location where the MACRO name is invoked
>>       but uses DIFFERENT code depending on what parameters were
>>       used when the MACRO name was invoked.
>> 
>>    You should now be able to answer the question; can I use a function
>>    call instead of a MACRO.
>>    The only thing that is complicated is determining what exactly
>>    the MACRO is used to accomplish.
>> 
>>   I hopes this clears this up for you.
>> 
>>   Bernie

I got that all down, i know what macros are and how they can be used, BUT i do
not know a lot about C other than syntax and the actual programming. what i mean
is i dont know the things like linking and library compiling and stuff like
that. 

What i meant about "why they did not use routines instead" was really
oriented to just my situation, not in general. For what im doin, macros really
were not needed, they actually *could* have used routines instead.

Its all complicated and rather stupid (my question) but i do (mostly)
understand. You actually did make those definitions a little more clear and now
i understand *better* :)

-- 
evil, corruption and bad taste
^[cense]

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu