i always forget how pointers acutally work so here's a cheatsheet:
int m = 400;
int *ptr = &m; // that means you declared a pointer that stores a memory address of m
printf("%p", ptr) // %p stands for pointer, and the syntax here says to dereference the pointer, to get the value from the address that the pointer held.
print("%p", &ptr) // &ptr is the address where to ptr pointer is stored. also works with usual variables like m, so &m would print the address to the m variable
**ptr is a pointer to a pointer
*char ptr and char *ptr are identical
also, sometimes you'll need to declare a pointer and use it as a variable, like here for example:
GLFWwindow* window = glfwCreateWindow(640, 480, "Triangles", NULL, NULL);
you need to declare a pointer instead of regular variable here because the function glfwCreateWindow returns a pointer itself.
a data structure can be a pointer itself
main(int argc, char** argv) i don't know why we even need that but fine, it doesn't really ruin the program since it doesn't have to be referenced when opening it. but if you really don't expect any command arguments for the program to run, just do main(void)
по сути, printf("hello world"); может спокойно работать, и не надо никаких переменных назначать. и кастовать дататипы тоже можно во время того как ты зовешь метод, и если ты впишешь например число после того что ты хочешь чтобы запринтилось, оно автоматом скажет мол это инт. то есть, printf("hello world, meaning of life is %d. The next 2 numbers are %c and %d", 42, (char)44, 46); выдает "hello world, meaning of life is 42. The next 2 numbers are , and 46"
@aomame336, another thing about pointers: sometimes they are a child or a parent object of a struct, a class. so you can use -> for dereferncing child objects of what you just dereferenced.
here's an example:
if (device) {
device->lpVtbl->Release(device);
}
the device variable holds a pointer to a COM object, and every COM object has a Release() method to clean up the object from memory. considering it's a COM object, you need to dereference lpVtbl, which is a pointer to a table with lots and lots of COM functions, and then dereference Release() from that table.
COM (Component Object Model) is a microsoft-developed framework for building and interacting with software components, that are mainly from microsoft. that includes dx11 and even windows api.
you can check if something's an com object if you inspect its header file and the object has to do with IUnknown , which is a base interface (or you could just call it a library/class) for every COM object.
also, there are common methods used with IUnkown, such as Release() and AddRef()
*char ptr and char *ptr are identical
@aomame336main(int argc, char** argv)
i don't know why we even need that but fine, it doesn't really ruin the program since it doesn't have to be referenced when opening it.but if you really don't expect any command arguments for the program to run, just do
main(void)
printf("hello world");
может спокойно работать, и не надо никаких переменных назначать. и кастовать дататипы тоже можно во время того как ты зовешь метод, и если ты впишешь например число после того что ты хочешь чтобы запринтилось, оно автоматом скажет мол это инт.то есть,
printf("hello world, meaning of life is %d. The next 2 numbers are %c and %d", 42, (char)44, 46);
выдает "hello world, meaning of life is 42. The next 2 numbers are , and 46"@aomame336, another thing about pointers: sometimes they are a child or a parent object of a struct, a class. so you can use->
for dereferncing child objects of what you just dereferenced.here's an example:
the device variable holds a pointer to a COM object, and every COM object has a Release() method to clean up the object from memory. considering it's a COM object, you need to dereference
lpVtbl
, which is a pointer to a table with lots and lots of COM functions, and then dereference Release() from that table.COM Objects
COM (Component Object Model) is a microsoft-developed framework for building and interacting with software components, that are mainly from microsoft. that includes dx11 and even windows api.you can check if something's an com object if you inspect its header file and the object has to do with
IUnknown
, which is a base interface (or you could just call it a library/class) for every COM object.also, there are common methods used with IUnkown, such as Release() and AddRef()