3

Is there any portable way in C++ to ensure that for a bunch of functions that are subsequent in the source code or generated from the same function template the compiler will generate them "one after another" as a contiguous region in memory in the resulting binary image?

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
SasQ
  • 14,009
  • 7
  • 43
  • 43
  • 3
    wicked question. But actually quite interesting. – UmNyobe Apr 20 '21 at 09:38
  • 1
    Maybe helpful: https://stackoverflow.com/q/6614209/1810087 – user1810087 Apr 20 '21 at 09:49
  • 1
    There is no *portable* way, no. – Remy Lebeau Apr 20 '21 at 10:05
  • "Portable" would presume that the code space is some sort of contiguous memory to start with, which is already a tricky assumption for _data_ in C++. You can't do pointer arithmetic on function pointers. Even figuring out _if_ functions are stored contiguously is not portable. – MSalters Apr 20 '21 at 11:22
  • Also, quite a few linkers will insert padding to align functions, so the *contiguous* part is very likely to break. – MSalters Apr 20 '21 at 11:24
  • The answer you got wasn't from the linked duplicate? – smac89 Apr 22 '21 at 02:31
  • 2
    I understand that you're frustrated, but that edit you made isn't appropriate. Note that we have an official [code of conduct](https://stackoverflow.com/conduct). Be nice, and watch your language. – ChrisGPT was on strike Apr 22 '21 at 11:31
  • 1
    I don't have the power to delete your account and I wouldn't want to do that even if I could. But there's a good chance a moderator will _lock_ your account if you keep editing in that kind of content. Instead of ranting, why not add an edit explaining why the dupe isn't a dupe so we can vote to _reopen_ your question? – ChrisGPT was on strike Apr 22 '21 at 14:09
  • 1
    "There's one condition though: I want all of my answers deleted along with my account"—you don't get to demand that. [You licensed all of the content you posted under a Creative Commons license](https://stackoverflow.com/help/licensing). You can't revoke that license. – ChrisGPT was on strike Apr 22 '21 at 14:11
  • The standard does not assume that functions occupy memory, or that they are stored in any sort of binary image, or that there is a compiler. You cannot even ask this question in a portable way. – n. m. could be an AI Apr 22 '21 at 14:23

0 Answers0