PHP在C / C isset()函数的对口++ [英] Counterpart of PHP's isset() in C/C++
问题描述
PHP有一个非常好的功能,使用isset($ VARIABLENAME)。它检查是否$ VARIABLENAME在程序中已经定义或没有。
PHP has a very nice function, isset($variableName). It checks if $variableName is already defined in the program or not.
我们可以建立C / C类似的功能++(某种符号表的查找)?
Can we build similar feature for C/C++ (some kind of symbol table lookup)?
推荐答案
我是一个C ++的家伙,但我记得在PHP中使用isset是用来检查一个变量包含通过GET / POST请求的传入,当值(我敢肯定还有其他的用途,但是这是一个常见的一种,我相信)。
I'm a C++ guy, but I remember in PHP isset is used to check if a variable contains a value when passed in through a get/post request (I'm sure there are other uses, but that's a common one I believe).
您真的没有什么动态类型在C ++中。所以你不能突然使用你没有previously明确定义的变量名。真的是因为在C ++中未设置变量没有这样的事。
You don't really have dynamic typing in C++. So you can't suddenly use a variable name that you haven't previously explicitly defined. There really is no such thing as an "unset" variable in C++.
就算你说诠释变种;不要初始化,变量有一个值,通常是垃圾,但在PHP意义上,它仍然套。
Even if you say "int var;" and do not initialize it, the variable has a value, usually garbage, but it's still "set" in the PHP sense.
我想的关闭将是preprocessor的#IFDEF和的#ifndef只检查是否已经定义使用#define的变量。但在我的经验,这是主要用于省略或添加基于标志code。例如:
The closes I suppose would be the preprocessor's #ifdef and #ifndef which only checks to see if you've defined a variable using #define. But in my experience this is mostly used for omitting or adding code based on flags. For example:
// code code code
#ifdef DEBUG
// debug only code that will not be included in final product.
#endif
// more code more code
您可以使用#define以确定是否包含调试code现在定义DEBUG。
You can define DEBUG using #define to determine whether to include "DEBUG" code now.
也许讲一点有关你想与使用isset的C ++相当于会给你如何去这样做的C ++之路更好地知道该怎么做。
Perhaps telling a bit more about what you're trying to do with the C++ equivalent of isset will give you a better idea of how to go about doing it "The C++ Way".
这篇关于PHP在C / C isset()函数的对口++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!