可以定义一个可以用作左值的函数 [英] Possibility to define a function that could be used as lvalue
问题描述
是否可以定义一个可以用作
func()= 2的函数;
我知道在C ++中使用引用它可能是实现。
是否有可能在C?
Is it possible to define a function that could be used as
func() = 2;
I know in C++ using reference it could be realised.
Is it possible in C?
推荐答案
giuliano说:
giuliano said:
是否可以定义一个可用作的函数
func()= 2;
我知道在C ++中使用引用它可以实现。
是否可以在C?
Is it possible to define a function that could be used as
func() = 2;
I know in C++ using reference it could be realised.
Is it possible in C?
C函数返回rvalues,而不是对象。你不能为
rvalue赋值。但是,您可以这样做:
* func()= 2;
如果您准备好承担后果并且如果func返回一个指向适当类型对象的
指针。
-
Richard Heathfield
Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk
电子邮件:rjh在上述域名中, - www。
C functions return rvalues, not objects. You can''t assign a value to an
rvalue. You can, however, do this:
*func() = 2;
if you are prepared to live with the consequences and if func returns a
pointer to an appropriately-typed object.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Richard Heathfield写道:
Richard Heathfield wrote:
>
giuliano说:
>
giuliano said:
是否可以定义一个可用作<的函数br />
func()= 2;
我知道在C ++中使用引用它可以实现。
它可能在C中吗?
Is it possible to define a function that could be used as
func() = 2;
I know in C++ using reference it could be realised.
Is it possible in C?
C函数返回rvalues,而不是对象。你不能为
rvalue赋值。但是,您可以这样做:
* func()= 2;
如果您准备好承担后果并且如果func返回一个指向适当类型对象的
指针。
C functions return rvalues, not objects. You can''t assign a value to an
rvalue. You can, however, do this:
*func() = 2;
if you are prepared to live with the consequences and if func returns a
pointer to an appropriately-typed object.
或者一个宏:
extern foo * real_func(void);
#define func()(* real_func())
我已经看到errno以这种方式定义,以允许线程感知错误:
但你的警告仍然存在。
-
+ -------------------- ----- + -------------------- + ----------------------- +
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody / at\spamcop.net | www.fptech.com | < std_disclaimer.h |
+ ------------------------- + --------- ----------- + ----------------------- +
不要 - 邮寄给我:< mailto:Th ************* @ gmail.com>
Or a macro:
extern foo *real_func(void);
#define func() (*real_func())
I''ve seen errno defined in such ways, to allow thread-aware errors:
But your caveats still remain.
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don''t e-mail me at: <mailto:Th*************@gmail.com>
"朱" < br ******* @ gmail.comwrote in
"giuliano" <br*******@gmail.comwrote in
是否可以定义一个可以用作
$ b $的函数b func()= 2;
我知道在C ++中使用引用它可以实现。
是否有可能在C?
Is it possible to define a function that could be used as
func() = 2;
I know in C++ using reference it could be realised.
Is it possible in C?
为什么这篇文章有一些中文英文字体?
你需要一个宏,而不是一个函数。
int global_x
#define lvalue()global_x
Why is this post in some Chinese English character font?
You need a macro, not a function.
int global_x
#define lvalue() global_x
这篇关于可以定义一个可以用作左值的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!