This site is no longer active and is available for archival purposes only. Registration and login is disabled.

onexit.c and my bad programming style


Postby UMCPmatt » Jul 30, 2002 @ 5:14am

int *i;

i is a pointer to an integer. What does i point to? Nothing, as we have not initialized that variable. There is no integer at that point, thus you cannot say something like *i=123; because i points to undefined memory. If you did the following:
int j;
i=&j;

but could I say

&i=&j

???

Then i is a pointer to j. You could of course dynamically allocate some memory as well:

int *i=new int;
or
int *i = malloc(sizeof(int));

ok that makes sense

The point is that

int *i;

is certainly not a shortcut for

int i;
&i;

Regarding your code excerpt, every MFC application has a class derived from CWinApp which contains the application's entry point. CWinApp is derived from CWinThread - after all, your main instance is just your application's primary thread. CWinThread contains the m_pMainWnd data member.


what do I need to include so that my source file SEES m_pMainWnd?


Dan East
[/quote]
UMCPmatt
 


Postby Dan East » Jul 30, 2002 @ 3:01pm

User avatar
Dan East
Site Admin
 
Posts: 5264
Joined: Jan 25, 2001 @ 5:19pm
Location: Virginia, USA


..

Postby UMCP_matt » Jul 30, 2002 @ 8:34pm

UMCP_matt
pm Member
 
Posts: 35
Joined: Jun 29, 2002 @ 4:25am
Location: sterling, va


Postby angedelamort » Jul 30, 2002 @ 10:30pm

User avatar
angedelamort
pm Member
 
Posts: 304
Joined: Mar 7, 2002 @ 11:16pm
Location: Montreal, Quebec


i tihnk you got it

Postby UMCP_matt » Jul 30, 2002 @ 11:44pm

i seem to be getting confused cause I forget about how x is intialized..

so when I see

&x I ALWAYS tihnk address of x

but i think this is only the case if x is initialized like

int x;

but if it is intialized like

int *x

THEN x is ALREADY the address so saying &x makes no sense..

am I getting it?

I use pointers all the time I am hoping once I really understand what I am doing everything will make more sense.

so

char *x

x is the address that contains the character

so to assign it a value I say

*x = 'c';

yes?

what if I wanted a string.. I would say

*x = "something";

and

x[3] = 'e';

right?
UMCP_matt
pm Member
 
Posts: 35
Joined: Jun 29, 2002 @ 4:25am
Location: sterling, va


Postby Digby » Jul 31, 2002 @ 3:18am

You're still confused (and wrong) in your assumptions.

int *x;

&x certainly makes sense. It's taking the address of a pointer variable that points to an int.

In your other case:

char *x;

*x = 'c';

This is horrible as you're storing the character 'c' into an unknown memory address that most certainly doesn't belong to your application. "Oh bartender, another pint of 0xC0000005 Access Violation please..."

The best thing for you to do is to write some simple lines of C code assigning values to various variables and then look at the values in the debugger and the memory watch window when you step through your app until you understand what is happening.
Digby
pm Insider
 
Posts: 1011
Joined: Apr 29, 2001 @ 1:53pm


Postby angedelamort » Jul 31, 2002 @ 4:08am

User avatar
angedelamort
pm Member
 
Posts: 304
Joined: Mar 7, 2002 @ 11:16pm
Location: Montreal, Quebec


Postby Dan East » Jul 31, 2002 @ 5:06am

User avatar
Dan East
Site Admin
 
Posts: 5264
Joined: Jan 25, 2001 @ 5:19pm
Location: Virginia, USA


ok ill put it in the debugger

Postby UMCP_matt » Jul 31, 2002 @ 7:49pm

UMCP_matt
pm Member
 
Posts: 35
Joined: Jun 29, 2002 @ 4:25am
Location: sterling, va


Previous

Return to Windows Mobile


Sort


Forum Description

A discussion forum for mobile device developers on the Windows Mobile platform. Any platform specific topics are welcome.

Moderators:

Dan East, sponge, Digby, David Horn, Kevin Gelso, RICoder

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron