What do I call a "normal" variable?
int* p;
int& r;
int i;
double* p2;
double& r2;
double d;
p and p2 are pointers, r and r2 are references, but what are i and d? (No, I am not looking for the answer "an int and a double")
I am looking for a name to use for "normal" variables, setting the开发者_运维百科m apart from pointers and references. I don't believe that such a name doesn't exist (after all, I can't be the first one who wants to distinguish them from pointers and references. I do have the feeling that it's something really easy and I'm just missing it here.
Who knows what to call "normal" variables?
Additional info
I am looking for a name that can refer to anything but references and pointers, so including classes. The whole same story could be held when the following was included as well:
MyClass* p3;
MyClass& r3;
MyClass c;
I am not looking for a way to refer to i
, a way to refer to d
and a way to c
. I am looking for a way to refer to the group (of non-references, non-pointers) which i
, d
and c
are part of.
If I understand what you are talking about, I would call it a value type.
Pointers and references are variables as well. I think it is sufficient to say that i is a variable of type int
and p is a variable of type pointer to int
. If they are members of a class i is a member variable of type int
would be the most precise description.
Edit: There is no definite answer to your question. int
would be a fundamental type
in standard terminology. Other types as classes, unions and pointers are called compound types
. This just isn't helpful in your case as you would refer to
A* a;
int* b;
A c;
as only consisting of compound types. But you want to emphasize that you use pointers. Just say it.
If you want the official terminology, then the C++ standard defines:
- fundamental types, built-in value types such as
int
anddouble
, and - compound types, including pointers and references, and also arrays, functions, classes, unions and enumerations.
It also uses the terms "object types", "reference types" and "function types", but it seems a bit vague to me about whether a pointer is an "object type" or a "reference type".
If you want to include fundamental types and classes, I would use the term "object type", and leave it to pedants to quibble about whether that should include pointers.
Value types (value variables) was my first thought, but it seems to make some people uncomfortable, so nonreferential types (nonreferential variables) works just as well: pointers and references are both "referential types" in the sense that they refer to another location, while ordinary value types do not.
They are just variables. Not pointers and not references, variables.
I think you want to use "non-pointer and non-reference type". There is no name especially designed for your purpose, i think.
A name which allows me to say, I am using pointers all over the place, but there in many cases there is no reason to do so, so I should change them to s wherever possible.
It sounds to me you look rather for "pass by copy" or "copy" vs "pass by reference" or "reference". The fact that you can pass a pointer by value makes it impossible to use an absolute term, but makes it necessary to use a term tied to the usecase:
int **p;
Is this a variable used to change a pointer of type int*
(then it would be "pass by reference" in the sense you aim to modify the referent. To clarify that a pointer is used, you may wish to use the term "pass by pointer" too), or is this variable just used to hold a value of type int**
(then it would be "pass by value" in the sense that you copy such a value)?
Values, or variables.
I typically call those "plain ol' data" (POD) variables, after the convention of referring to a struct
as "POD" if it contains only data members (no functions). That's not an official convention, but it gets the point across (for simple types like int
and float
, it doesn't apply for classes).
I have also heard these types of variables called "concrete" variables. I think the distinction that was trying to be made is that these variables are something in and of themselves, whereas pointers and references simply tell you about some other piece of data somewhere else.
More than anything else, I hear these "loose" variables (that is, not a member of another object) referred to simply by their type (integer, floating-point number, class, etc).
i
and d
are consistently called objects in the C++ standard. But, then again, so are p
, p2
, and objects of class type such as the "c" of MyClass c;
.
Personally I like calling i
, d
, and p
objects, though it might be a little bit confusing to programmers of other languages such as Java, where they would be known as primitive variables with the term objects reserved for instances of classes.
EDIT: Instead of
I am using pointers all over the place, but there are many cases where there is no reason to do so, so I should change them to <normal variable>s wherever possible.
I would say: "I am using pointers all over the place, but there are many cases where there is no reason to do so, so I should remove the levels of indirection wherever possible."
I think we should call them OBJECTs. I think it's no need to be that strict.
Consider:
typedef int *, pint;
pint foo;
What do you think foo is?
精彩评论