• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

elis-cool

Pointers

9 posts in this topic

The book im reading could be better at explaining pointers and their use so could some people help?. So if you had: int* var = &5; cout << var; You would say intiger that points to var is at the address of 5??? And would it show the hex value of the address (var)in memory? So * means what exactly? (not multiply) And & means the address of? So what does ''pointer'' acctually mean? I really need the help with pointers as Im finding them a bit hard along with the hexadecimal system.
0

Share this post


Link to post
Share on other sites
take this ''analogy'' someone gave me.

a fly flies. a pointer points.

lets say you have

int i = 5 ;
int* ptr ;

ptr = &i


thus

ptr now holds the ADDRESS of i.
now to display the address, you simply do this:

cout << &ptr ; // which will display the value of the pointer

now if you want to change the value of i..you can do this:

*ptr = 100

hope this isnt too confusing!

0

Share this post


Link to post
Share on other sites
do NOT set the memory location of the pointer manually! leave it alone! it will be automatically set when you point to something.

just remember...a pointer just points to memory.

int i = 100

i gets stored somewhere in memory...and when you ''point'' to that ,like in the example above, you find WHERE its located in memory! and from there you can do a lot of cool stuff...ull learn that later on though if you have questions, im me at "damn messycan" or y!"damn_messycan"

0

Share this post


Link to post
Share on other sites
I think that what you are doing is itself confusing.

First of all, when you assign a type to a variable you attach a * to the variablename when you want a pointer. The pointer is a variable but holds only the address of a memory area that stores a type.

int *var; //holds a memory location not yet assigned
EDIT: I must be drunk or something

int var=5; //var stores the integer value 5
int *pointer;
pointer = &var; //A pointer stores an address right? And var stores an integer right? To get the address of var you use a &.

If you have a pointer (an address to a memory location) and you want the actual value at that memory location you dereference it like so:
cout << *pointer; //this prints the value
cout << pointer; //This prints the memory location
cout << var; //this prints the value
cout << &var; //This prints the memory location

And I would be surprised if you could do int *var=&5; because here, 5 is a constant, but I might be wrong.

By the way, some advice: when you declare a pointer, put the * sign next to the variable name and not the type. Why, it doesn´t matter? Well, declare two pointers like this:

int* var1, var2;

Are they both pointers? - No´.
It is just easier to see that var1 is a pointer and var2 not like so:
int *var1, var2;

Good luck;

Why make it simple when you can make it sooo nice and comlicated.

Edited by - clabinsky on January 11, 2002 7:34:29 PM
0

Share this post


Link to post
Share on other sites
quote:

cout << &ptr ; // which will display the value of the pointer



Last time I checked this would display the address of ptr and actually the same as only using ptr

Declaring a pointer use: *
Dereferencing pointer use: * //getting the value
Getting the address of a var use: &

Remember the pointer holds the adress. You dereference it with * to get the value.

Why make it simple when you can make it sooo nice and comlicated.

Edited by - clabinsky on January 11, 2002 7:36:13 PM
0

Share this post


Link to post
Share on other sites
Thanks its been a bit of help...
So is declaring it a pointer ie. int *var; a different variable type to int,char,double,long?

And what is all this "cool stuff" you can do? so far all i can see it good for is overwriting a variable in memory, but why would anyone even want to do this instead of just changing the value of the variable eg
char letter = ''n'';
to
char letter = ''p'';
why do it with pointers?

And maybe you could use it to possibly crash other programs running by you overwriting a int with a double to destroy the memory around it(if its got anything stored there).
0

Share this post


Link to post
Share on other sites
Sigh....

Well, first of all you have to declare the type of the pointer because you are telling the pointer that it will be pointed to a certain type - different types = different amount of memory needed and operations are done differently.

Basically, the cool thing is that you can change to where a pointer points without losing the data and when you are dealing with big structures you (usually) don´t want to send copies of the structure when calling a function for example.
    
struct mystruct
{
char *szName;
int iAge;
float fHeight;
...
};

void somefunction1(mystruct a, bool bFlag);
void somefunction2(mystruct* a, bool bFlag);
void somefunction2(const mystruct* a, bool bFlag);

int main()
{
mystruct Obj1;

mystruct.szName="clabinsky";
int iAge=30; //Oh my god, time passes fast ;)

float fHeight=5.32f
...

//This call copies the whole struct when the function is

//called. Any changes you make will go out of scope when you

//return.

somefunction1(Obj1,false);

//This call however only calls the function with the address

//of the struct allowing changes to be made permanently and

//a pointer is 4 bytes in size as opposed to the struct...

somefunction2(&Obj1,false);

//if you want to send the address of the struct but not

//allow any changes you should use the keyword const like so

somefunction3(&Obj1,false);

return 0
}



I am actually using C here where C++ is easier because it allows you to declare the functions with a & instead of the * and when you call the function you don´t have to specify the &Obj1 only Obj1.

Trust me, pointers are cool.

EDIT: I forgot something:
int *ptrtoaninteger;
Read it out loud ptrtoaninteger is a pointer to a memory location containing an integer. The pointer contains the address (memory location) to an integer (if initialized). If I dereference the pointer using a * I will get the value of the integer just like using a normal variable.

Why make it simple when you can make it sooo nice and complicated.

Edited by - clabinsky on January 11, 2002 8:09:32 PM
0

Share this post


Link to post
Share on other sites
Thanks for the help so far guys but the one thing i''m stuck on now is how exactly do you read pointers as; eg:

int *var = 5; // but what would this be read as?
int ptr = &var; // would be read as int ptr = the address of var.
*ptr = 8; // and what would this be read as?

Also what exactly is the difference between:
*num = 3; and this: num = 3; while num is a pointer?

Sorry for all the qestions but im just not getting it. How many others here had trouble with pointers? I just dont know why you would use a pointer instead of changing the variable normally. Exept when passing vaiables to a function.
0

Share this post


Link to post
Share on other sites
quote:
Original post by elis-cool
Thanks for the help so far guys but the one thing i''m stuck on now is how exactly do you read pointers as; eg:

int *var = 5; // but what would this be read as?
int ptr = &var; // would be read as int ptr = the address of var.
*ptr = 8; // and what would this be read as?

Also what exactly is the difference between:
*num = 3; and this: num = 3; while num is a pointer?

Sorry for all the qestions but im just not getting it. How many others here had trouble with pointers? I just dont know why you would use a pointer instead of changing the variable normally. Exept when passing vaiables to a function.


OK... I think you have confused yourself.

All the familiar types like char, int, float etc. contain data.
The following trivial examples all show some data being stored.

int i = 5;
int j = 4;
float f = 5.6;
char c = ''H'';

Pointers do not store data. Instead, they store the memory address of something which does store data.

int* pi = &i; // pi points to i;

Now if you change the value of the pointer itself, you are changing the area in memory it is pointing at, which may not be what you want to do. In order to change the data it is pointing at, you need to dereference it....

eg...

*pi = 10 // this changes the value of i to 10.
pi = j // this changes the pointer to point at memory location 0x4 (because the value currently stored in j is 4) which is probably not what you wanted to do. Most compilers would warn you about this particular error.
pi = &j // Now pi actually points at j.
*pi = 10 // now j has a value of 10 as well.

Hopefully that will clear some things up for you. Either that or it will confuse you more, I am not sure.



0

Share this post


Link to post
Share on other sites