分配变量时获取变量的地址合法吗?

发布于 2025-01-06 07:29:19 字数 98 浏览 2 评论 0原文

我想做这样的事情:

void* ptr = some_function(&ptr);

这在 C 中合法吗?

I want to do something like this:

void* ptr = some_function(&ptr);

Is this legal in C?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

憧憬巴黎街头的黎明 2025-01-13 07:29:19

是的,这是完全合法的。请注意,您的 some_function 将需要具有此签名:

void* some_function(void** param)

Yes, it's totally legal. Beware that your some_function will need to have this signature :

void* some_function(void** param)
回忆躺在深渊里 2025-01-13 07:29:19

这是明确定义的。没有明确定义的是取消引用 some_function 中的指针。

That is well-defined. What would not be well-defined would be to dereference the pointer in some_function.

我是男神闪亮亮 2025-01-13 07:29:19

是的。这是正确的。

您有具体问题吗?

Yes. It is correct.

Do you have a specific problem?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文