C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Expose architecture at compile-time (and more at runtime)

From: Thiago Macieira <thiago_at_[hidden]>
Date: Thu, 27 Oct 2022 09:21:18 -0700
On Thursday, 27 October 2022 03:22:40 PDT Frederick Virchanza Gotham via Std-
Proposals wrote:
> ( Feature 1 ) Allow the use of the 'sizeof' operator on a function to
> get the byte count of the function's machine code. This would allow us
> to copy a function in memory, edit a constant in the machine code, set
> the memory page as executable and execute it. Currently we can pull
> this off by first doing an 'objdump' on the object file to see the
> size of the function, but it would be nice if we could do all this in
> C++ code. Of course this all only makes sense on computers where
> program memory and data memory are the same thing (and sizeof(void*)
> == sizeof(void (*)(void))) -- which it is on the majority of
> computers. Something like as follows:
>
> int Func(void); // defined elsewhere

This is impossible.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2022-10-27 16:21:22