Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6993105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:43:17+00:00 2026-05-27T19:43:17+00:00

This is relating to the flurry of object-oriented C postings, but differs in that

  • 0

This is relating to the flurry of object-oriented C postings, but differs in that I don’t want all the features, just one:

An ability to do this:

struct foo { 
  int (*bar)(void);
  char baz;
};

An then have the back-reference. C has a calling convention called cdecl; basically pushes arguments on to the stack, has a return pointer, then jumps to some address. The code at that address pops arguments off the stack and goes on its merry way.

The thiscall convention is slightly different in that it adds one extra argument, a “this” pointer, implicitly.

Since you can start executing arbitrary byte code in C quite easily AND since gcc supports inline assembler templating, this sounds like you could just make some macro so that you could do something like:

int bar(void) {
  GETTHIS;
  cThis->baz = 0;
}

int createFoo(struct Foo*pFoo) {
  ASSIGN(pFoo, bar);
} 

Basically what ASSIGN would do is sidestep cdecl in someway to emulate a thiscall style convention and then what GETTHIS would do is the other side of the accounting trick.

I was wondering if:

  • A solution to this exists and
  • If not, if there’s a reason why it can’t be done

Just this alone; the convenience of true “We’re all consenting adults here” style member functions, would be simply awesome. Thanks!

Notes:

  • I’m just talking x86, linux, gcc here … I know the world is a wide and strange place.
  • This is out of pure curiosity.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:43:18+00:00Added an answer on May 27, 2026 at 7:43 pm

    My friend eventually got it: https://gist.github.com/1516195 … requires specifying function arity and is limited to x86_64 … but yes, it’s a pretty nice compromise that makes things really unobtrusive.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am aware that a thousand and one questions relating to this topic have
I found only one thread relating to this but it did not answer the
I think I read every single web page relating to this problem but I
I'm aware of several question on this forum relating to this. But I'm not
I know that there are a few Questions here on SO relating to this,
This is relating to the following: (In Python Code) for i in object: doSomething(i)
I've seen lots of posts on SE relating to this, but none have answered
This question is relating to a specific functionality that a client has requested for
There are a few questions relating to this topic but nothing quite the same
I had posted other questions relating to this problem, but haven't had any responses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.