Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Standard library macros

Reply
Thread Tools

Standard library macros

 
 
Keith Thompson
Guest
Posts: n/a
 
      11-14-2010
Nobody <(E-Mail Removed)> writes:
> On Sat, 13 Nov 2010 21:10:15 +0000, sandeep wrote:
>> Obviously the implementation can "work magic" and do anything by
>> functions.

>
> No it can't. You're not talking about "functions", but "special forms".
> Just because something uses the syntax "name(argument list)", that doesn't
> make it a function.
>
> There isn't a single *function* in the standard which requires special
> treatment from the compiler. Anything which looks like a function either
> can be implemented in a library on any sane platform or is a macro.
>
>> But the true point is that if the problem is not being able to pass type
>> names to functions, but being able to pass them to macros, why not
>> improve the language to allow *all* functions (both implementation and
>> user functions) to accept type names as arguments? This would also be
>> very helpful for type-generic / template-based programming which is now
>> very difficult in C.

>
> If you want C++, you know where to find it.


I don't think C++ functions or templates can implement offsetof()
(which takes a member name as an argument) or assert() (which
requires source level information from the point of invocation)
any better than C can.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
 
Malcolm McLean
Guest
Posts: n/a
 
      12-04-2010
On Dec 4, 10:24*am, (E-Mail Removed) (Gordon Burditt) wrote:
>
> There are a couple of cases, such as getc() and putc(), where a
> macro implementation was allowed to evaluate its argument more than
> once. *These were allowed for efficiency issues. *Where it actually
> makes a difference, I'm not so sure the efficiency issue has actually
> gone away.
>

I never use getc(), and the efficiency difference with fgetc() has
never been a problem.


 
Reply With Quote
 
 
 
 
jacob navia
Guest
Posts: n/a
 
      12-04-2010
Le 13/11/10 03:13, Eric Sosman a écrit :
> On 11/12/2010 5:58 PM, sandeep wrote:
>> Hi
>>
>> We know that for historical reasons, many utilities provided by the
>> standard library *must* be implemented as macros instead of functions, ie
>> assert, the va_arg commands, offsetof, getchar... This was to remove the
>> function call overhead which was a significant inefficiency on the slow
>> processors around in the early days of C.
>>
>> We also know that these efficiency concerns no longer matter so much, and
>> also the ISO Standard itself has recognised that macros are undesirable,
>> by introducing a better alternative (inline functions).
>>
>> I would therefore propose that in the next ISO Standard, all standard
>> library commands are required to be implemented as functions, possibly
>> inline, and not as macros. This will lead to better type safety and avoid
>> problems with multiple evaluation side effects.

>
> Show us your implementations of offsetof(), setjmp(), and
> assert() as functions, and *then* we'll talk.
>


For an implementation of setjmp as a function see lcc-win.

 
Reply With Quote
 
Peter Nilsson
Guest
Posts: n/a
 
      12-04-2010
Eric Sosman <(E-Mail Removed)> wrote:
> ...
> * * *Show us your implementations of offsetof(), setjmp(), and
> assert() as functions, and *then* we'll talk.


There are quite a few implementations of setjmp() as a function.
What surprises me is that longjmp() is required to exist as a
function.

--
Peter
 
Reply With Quote
 
Peter Nilsson
Guest
Posts: n/a
 
      12-04-2010
> Keith Thompson writes:
> > sandeep <(E-Mail Removed)> writes:


<snip more beer milkshakes>

sandeep <(E-Mail Removed)> wrote:
> Sometimes I imagine that you and Mr Sosmanji just look for
> reasons to oppose my suggestions...


Well someone has to, because you clearly don't.

--
Peter
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Standard Library macros Raj Pashwar C Programming 3 07-20-2012 06:55 AM
standard library headers without excessive macros K4 Monk C Programming 3 03-03-2011 05:23 AM
Explanation of macros; Haskell macros mike420@ziplip.com Python 80 11-07-2003 02:22 AM
Re: Explanation of macros; Haskell macros mike420@ziplip.com Python 5 11-01-2003 01:09 AM
Re: Explanation of macros; Haskell macros mike420@ziplip.com Python 1 10-07-2003 04:07 PM



Advertisments