This question already has answers here:
What is std::decay and when it should be used?
(2 answers)
Closed 6 years ago.
We know that compiler will decay array/function to pointers when needed(according to context), then when is the time we should explicitly use std::decay?
Is there any task that requires us to use it, or else, compiler doesn't know how to handle it?
Thanks.
Simply put, decay::type is the identity type-transformation except if T is an array type or a reference to a function type. In those cases the decay::type yields a pointer or a pointer to a function, respectively.
For more detail please see this https://stackoverflow.com/a/25732651/1691223
Related
This question already has answers here:
When should I pass or return a struct by value?
(9 answers)
Closed 7 years ago.
I know the difference between pass by value and pass by reference. I use them and understand how they work in the codes that I've dealt so far. However, I'm looking for a general rule. What is generally the best time to use pointers and what is the best to use actual values? Examples are much appreciated.
As a general rule, pass-by-value for basic types (int, char, etc.), and pass-by-pointer (or better, pass-by-reference) for big data as struct.
Thinking of a struct with 1000 data members, and the cost to copy that gigantic data to a function. It'd be much quicker to pass-by-pointer or pass-by-reference in that case.
This question already has answers here:
what is causing SIGSEV?
(3 answers)
Closed 8 years ago.
I am getting an overflow for using this.
int x[471][640];
Someone told me to use Malloc? I have no idea what that is. Its not in my book nor my lectures. Any fix to this?
If you do not know yet about C function malloc then you can try another approach. For example declare your local array as
static int x[471][640];
that is as having static storage duration.
If you also do not know yet about the keyword static then the only approach I can suggest is to declare the array globally that is outside any function. for example before main:)
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
What is void* and to what variables/objects it can point to
What does void* represent in C?
Please give a reason for the use, too...
void * is a "typeless" pointer in C, that is, a pointer that may point to an object of any type. It is used if one does not know the type of the data to be stored beforehand.
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
What is the point of function pointers?
hi all,
I want to get the basic and concrete idea of function pointers in C language.
ie 1) its usage in C
2) main applications it is currently using
3) unique features
4) its scope in embedded applciations etc
Hoping your co operation in this too.
__Kanu
Function Pointers are pointers, that is variables, which point to the address of a function.
Nice example here. Also this answer is a must read.
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Static variable initialization?
why global variable in C takes zero as initial value?
This required for a compiler to conform to the C standard.
The reason for the design choice is likely that having random garbage in your uninitialized variables makes errors much harder to detect.