I found the following syntax in a c++ source file (not header):
template <typename Type_> static void aFunction(Type_ &function, ...) {
uintptr_t value(astruct.val); //confusing
}
Is that confusing line in question a declaration for value? I tried writing a hello world program like:
int main(){ uintptr_t a(80); return 0;}
and it returns an expected declaration specifiers or ‘…’ before numeric constant, may i know what does that confusing line do? Thanks!
Edit: I think i should reveal the full function declaration:
template <typename Type_>
static void nlset(Type_ &function, struct nlist *nl, size_t index) {
struct nlist &name(nl[index]);
uintptr_t value(name.n_value);// this is the confusing line
if ((name.n_desc & N_ARM_THUMB_DEF) != 0)
value |= 0x00000001;
function = reinterpret_cast<Type_>(value);
}
uintptr_t is an unsigned integer (at least) the size of a pointer.
It is not a native type though and you need to include
<stdint.h>or<cstdint>Really it is “evil” to cast pointers to ints and store them as integral variables but there is a lot of “legacy” code that does it and relies on it, and so you need an int size big enough to store it.
Storing them as integers allows you to do things you can do with ints “safely” but not with pointers, such as compare them when they are not part of the same range, in order to use them in memory-leak checkers, etc.