🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #4342

Re: "Overloaded" function in C

#4342
From: Greg Comeau
Date: Tue, 07 Nov 1995 22:59
39 lines
1652 bytes
In article <47m4dl$eje@gaia.ns.utk.edu> elemings@unix1.utm.edu (Eric Lemings) writes:
>#include <stdio.h>
>
>#define f(x, y) ((x) / (y))
>
>int (f)(int x, int y, int z)
>  {
>  return (x * y + z);
>  }
>
>int main(void)
>  {
>  int a = f(9, 2);
>  int b = (f)(9, 2, 4);
>
>  printf("f(9, 2) = %d", a);
>  printf("(f)(9, 2, 4) = %d", b);
>
>  return (0);
>  }
>
>Hunting season is now open.  I tried this on a Standard C/Unix
>system compiler and it worked.  Not sure how useful it is though.

It has better work.  I suppose this does buy you one overload on
some names.  This is of course of little utility to most programs,
and works because of Standard C tokenization considerations and hence
hijacks it being recognized as a macro name.  When useful, it can buy you
things such as:
(1) It says "this is what I want" because a header or macro cannot
    override it.
(2) A pointer to a function-like macro is not possible and you'll need
    (at least) its prototype if a "real function" is somewhere.

- Greg
-- 
       Comeau Computing, 91-34 120th Street, Richmond Hill, NY, 11418-3214
 Here:comeau@csanta.attmail.com / BIX:comeau or comeau@bix.com / CIS:72331,3421
    Voice:718-945-0009 / Fax:718-441-2310 / Prodigy: tshp50a / WELL: comeau
Technical Details
Message-ID: <47oobp$jae@panix.com>
Path: arc1-ca.pugleaf.net!in2.uu.net!panix!not-for-mail
References: <47m4dl$eje@gaia.ns.utk.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in2.uu.net!panix!not-for-mail
From: comeau@panix.com (Greg Comeau)
Newsgroups: comp.std.c
Subject: Re: "Overloaded" function in C
Date: 7 Nov 1995 17:59:05 -0500
Organization: Comeau Computing
Message-ID: <47oobp$jae@panix.com>
References: <47m4dl$eje@gaia.ns.utk.edu>
Reply-To: comeau@csanta.attmail.com (Greg Comeau)
NNTP-Posting-Host: panix.com