1. What is #define? What does it do? 2. Could someone give me an example of why i would want to have them in a parameter, a simple example? Thanks for the help
2: Typedef = Type Definition. It means "This is how I define this data type".
Just notice that typedefs do not define new types. They simply allow you to use another name, an alias, for some type that already exists.
TpOreilly wrote:
Also, what exactly is a "macro" in programming? That word has come up quite abit.
In C and C++, a macro is a hack that performs textual substitution. In the Lisp family, a macro actually allows you to change program structure, though I've never used them.
FidgityParseLanguage wrote:
Well since the definition was already cleared, a more neat way of putting it would be: LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM)
That's not so neat if you need to actually use the arguments passed, which is the whole point of window procedures.
So as CALLBACK is a define of _stdcall is this not just giving it another name, how does it differ from typedef?
Preprocessor macros are not technically part of the core language. They just substitute text. Since __stdcall is not a type, it can't be typedef'ed, so macros are used to substitute the word CALLBACK for the word __stdcall before compilation.
AND what is the difference from variables inside a function and in the functions parameters.
There's no difference. Parameters are local variables, only they're initialized with the arguments passed when the function is called.
Define and Typedef have simular purposes but functionaly they are very different. If you try to use #define int myint you'll get a funny error from you compiler, and also if you try to enter #typedef MY_INT 5 niether one will work.
You use #define to when you want a piece of data to be both constant and global, that is to say it does not change AND it is readable by everything.
You use #typedef when you want to create a data type based off of another existing data type.
You use #typedef when you want to create a data type based off of another existing data type.
At the risk of being annoyingly repetitive:
filipe wrote:
Just notice that typedefs do not define new types. They simply allow you to use another name, an alias, for some type that already exists.
TpOreilly wrote:
What information is put into a "stack", when would we use the information in a stack?
A stack is just a LIFO (last in, first out) data structure, like a pile of dishes. When people refer to "the stack", they mean an inner structure that is used at runtime to keep track of function calls. Each function, when running (until it returns), has an activation record kept in the stack, which keeps track of its state. If a function calls another one, the new activation record is stacked over the old one, and so on.
To summarise on parameters, basically parameters are local variables, thing im finding hard to understand is why create them in the parameters, why not just create them inside the actual function itself?
You know how in math you can have a function f such that f(x) = x * x (or anything you might want to do with x)? x is a parameter. How can f know which x to create internally (so that it can calculate x * x) if its caller doesn't pass it the value as an argument? It's like saying: "I want to know f(4), but I just want to say f() and f is supposed to figure out I'm talking about 4, not 5, not 256, not 3.14159265358979."
Thanks, but i still dont know why create variables in the parameters, and not create them inside the actual function itself. Could you tell me how we would USE 'int a' differently if it were in the parameter, and in the actual function itself.