WndProc()

Pages: 123
Jan 19, 2011 at 1:05pm
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
Jan 19, 2011 at 1:08pm
closed account (z05DSL3A)
http://www.cplusplus.com/doc/tutorial/preprocessor/
Jan 19, 2011 at 1:53pm
Computergeek01 wrote:
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.
Last edited on Jan 19, 2011 at 1:56pm
Jan 19, 2011 at 3:23pm
So as CALLBACK is a define of _stdcall is this not just giving it another name, how does it differ from typedef?
Jan 19, 2011 at 4:37pm
AND what is the difference from variables inside a function and in the functions parameters.
Jan 19, 2011 at 5:53pm
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.
Jan 19, 2011 at 7:52pm
Thanks :)

So basically, #define and typedef do the same thing, but they are for different things?
Jan 19, 2011 at 7:55pm
So, if i wanted to give a type another name i would use typedef, but for everything else i use #define?

Also, yet another question...

What information is put into a "stack", when would we use the information in a stack?
Last edited on Jan 19, 2011 at 8:25pm
Jan 20, 2011 at 12:33am
???

p.s thanks for all the replies
Jan 20, 2011 at 4:18pm
Anyone
Jan 20, 2011 at 6:01pm
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.
Jan 21, 2011 at 1:32am
closed account (yAqiE3v7)
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.


All true, very smart. :)

I was going to say similar things, but you really got to the point very simple and easily. :)

Jan 21, 2011 at 3:44am
And as for the question on stacks :)
Jan 21, 2011 at 6:47am
closed account (yAqiE3v7)
Bummer.
Jan 21, 2011 at 2:27pm
Computergeek01 wrote:
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.
Jan 21, 2011 at 3:47pm
Thanks to everyone who replied
Jan 21, 2011 at 7:01pm
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?
Jan 21, 2011 at 7:27pm
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."
Jan 22, 2011 at 1:22am
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.

:)
Jan 22, 2011 at 4:41am
See the example below:

int addition (int a, int b)
{
int r;
r=a+b;
return (r);
}

why not just put:

int addition ()
{
int a,
int b
int r;
r=a+b;
return (r);
}

??

Pages: 123