Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #153161

Re: missing gcc attribute "overwritable"

From Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups comp.lang.c
Subject Re: missing gcc attribute "overwritable"
Date 2020-07-09 10:02 -0700
Organization A noiseless patient Spider
Message-ID <86o8oofwpc.fsf@linuxsc.com> (permalink)
References <caf83b9d-fb4a-46d4-81e5-28f28f3498e8o@googlegroups.com> <dfcd0fc5-141f-4132-a340-c0b2c41be7fbo@googlegroups.com> <cbc7dbde-4705-41ef-b4b0-d526b404ad95o@googlegroups.com> <45a3e0bc-dab7-4bf9-9ca8-5162978d1cbao@googlegroups.com>

Show all headers | View raw


mark.bluemel@gmail.com writes:

> On Friday, 3 July 2020 03:33:06 UTC+1, donal...@gmail.com  wrote:
>
>> On Thursday, July 2, 2020 at 1:56:33 PM UTC-4, aotto1...@gmail.com wrote:
>>
>>> Hi, this is a basic example -> not so difficult to implement :-)
>>>
>>> #include <stdio.h>
>>>
>>> __attribute__((overwritable))
>>> static int test (int i) {
>>>   return i+2;
>>> }
>>>
>>> // overwrite
>>> static int test (int i) {
>>>   return i+3;
>>> }
>>
>> // Written manually:
>> static int test (int i) {
>>    return i + 3;
>> }
>> #define OVERRODE_test
>>
>> // Written by generator:
>> #ifndef OVERRODE_test
>> static int test (int i) {
>>    return i + 2;
>> }
>> #endif
>>
>>> void main (void) {
>>
>> Bonehead.
>
> I dislike the preprocessor (blind prejudice, I'm sure) and wondered
> whether something could be done with function pointers, like a
> dispatch table.
>
> Calls should be through a function pointers, which the generated
> code would initialise and any hand-written code subsequently update.

If we accept the premise of the problem statement (that is, a way
to supersede an automatically generated function with a manually
written one), using function pointers has some, hmmm, let me say
inefficiencies.  For one, calls through a function pointer will
inhibit (with high probability) potential inline expansion.  Also,
any generated function that is superseded (but still has its
address taken for storing, if temporarily, in a function pointer)
will still be compiled and the code generated for it will (again
with high probability) still be present in the executable.

Even though some people may find it distasteful, the C preprocessor
is a fairly good match for solving the problem here (again under
the assumption that we accept the premise that the stated problem
is what needs to be solved).

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

missing gcc attribute "overwritable" aotto1968zwei@gmail.com - 2020-07-02 00:31 -0700
  Re: missing gcc attribute "overwritable" mark.bluemel@gmail.com - 2020-07-02 01:38 -0700
  Re: missing gcc attribute "overwritable" David Brown <david.brown@hesbynett.no> - 2020-07-02 12:03 +0200
  Re: missing gcc attribute "overwritable" Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-07-02 06:18 -0700
  Re: missing gcc attribute "overwritable" scott@slp53.sl.home (Scott Lurndal) - 2020-07-02 16:33 +0000
    Re: missing gcc attribute "overwritable" aotto1968zwei@gmail.com - 2020-07-02 10:57 -0700
  Re: missing gcc attribute "overwritable" Andrey Tarasevich <andreytarasevich@hotmail.com> - 2020-07-02 10:21 -0700
  Re: missing gcc attribute "overwritable" Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-07-02 10:42 -0700
  Re: missing gcc attribute "overwritable" aotto1968zwei@gmail.com - 2020-07-02 10:56 -0700
    Re: missing gcc attribute "overwritable" Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-07-02 11:33 -0700
      Re: missing gcc attribute "overwritable" Bart <bc@freeuk.com> - 2020-07-02 19:53 +0100
    Re: missing gcc attribute "overwritable" donalhambra@gmail.com - 2020-07-02 19:32 -0700
      Re: missing gcc attribute "overwritable" mark.bluemel@gmail.com - 2020-07-03 00:30 -0700
        Re: missing gcc attribute "overwritable" aotto1968zwei@gmail.com - 2020-07-03 00:36 -0700
          Re: missing gcc attribute "overwritable" mark.bluemel@gmail.com - 2020-07-03 06:32 -0700
            Re: missing gcc attribute "overwritable" mark.bluemel@gmail.com - 2020-07-03 07:08 -0700
        Re: missing gcc attribute "overwritable" Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-07-09 10:02 -0700
      Re: missing gcc attribute "overwritable" aotto1968zwei@gmail.com - 2020-07-03 00:37 -0700
        Re: missing gcc attribute "overwritable" richard@cogsci.ed.ac.uk (Richard Tobin) - 2020-07-03 15:30 +0000
          Re: missing gcc attribute "overwritable" The Real Non Homosexual <cdalten@gmail.com> - 2020-07-03 11:51 -0700
            Re: missing gcc attribute "overwritable" richard@cogsci.ed.ac.uk (Richard Tobin) - 2020-07-03 19:48 +0000
              Re: missing gcc attribute "overwritable" Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-07-03 14:20 -0700
                Re: missing gcc attribute "overwritable" Richard Damon <Richard@Damon-Family.org> - 2020-07-03 20:37 -0400
        Re: missing gcc attribute "overwritable" aotto1968zwei@gmail.com - 2020-07-05 01:34 -0700
          Re: missing gcc attribute "overwritable" Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2020-07-05 09:45 -0400
          Re: missing gcc attribute "overwritable" Manfred <noname@add.invalid> - 2020-07-05 20:23 +0200
          Re: missing gcc attribute "overwritable" James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-07-05 19:09 -0400
            Re: missing gcc attribute "overwritable" gazelle@shell.xmission.com (Kenny McCormack) - 2020-07-05 23:37 +0000
              Re: missing gcc attribute "overwritable" David Brown <david.brown@hesbynett.no> - 2020-07-06 08:27 +0200

csiph-web