Date: Thu, 20 Apr 2023 13:47:09 +0100
On Thu, Apr 20, 2023 at 12:32 PM Ville Voutilainen
<ville.voutilainen_at_[hidden]> wrote:
>
> Don't dereference null pointers, it's undefined behavior to do so.
As far as I'm aware, you can put as much undefined behaviour as you
want in a function, so long as you don't invoke it, right?
void Func(void)
{
int i = INT_MAX;
++i;
int *p = nullptr;
*p = 5;
}
A program containing the above function is __not__ illformed, and
everything is okay so long as the function isn't invoked.
In my previous post I had a function that was only ever defined in
order to use 'decltype' on it, and so whether or not its contents
would exhibit undefined behaviour doesn't matter.
Or am I missing something?
By the way I originally used 'declval' instead of dereferencing a
nullptr but I got a compiler error because GNU g++ doesn't allow you
to evaluate declval.
> > Was this kind of thing not supposed to be done? Or is it okay?
>
> It's perfectly okay.
This might have implications for my solution of creating thunks by
monitoring the frame pointer.
<ville.voutilainen_at_[hidden]> wrote:
>
> Don't dereference null pointers, it's undefined behavior to do so.
As far as I'm aware, you can put as much undefined behaviour as you
want in a function, so long as you don't invoke it, right?
void Func(void)
{
int i = INT_MAX;
++i;
int *p = nullptr;
*p = 5;
}
A program containing the above function is __not__ illformed, and
everything is okay so long as the function isn't invoked.
In my previous post I had a function that was only ever defined in
order to use 'decltype' on it, and so whether or not its contents
would exhibit undefined behaviour doesn't matter.
Or am I missing something?
By the way I originally used 'declval' instead of dereferencing a
nullptr but I got a compiler error because GNU g++ doesn't allow you
to evaluate declval.
> > Was this kind of thing not supposed to be done? Or is it okay?
>
> It's perfectly okay.
This might have implications for my solution of creating thunks by
monitoring the frame pointer.
Received on 2023-04-20 12:47:22