C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

structure's memory layout in the function?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Narendra
Guest





PostPosted: Thu Oct 19, 2006 9:10 am    Post subject: structure's memory layout in the function? Reply with quote



void function1(void *);
void main()
{
int size_offset = 0;
typedef struct
{
int a;
int b;
int c;
char ch;
}A;

A *pst = NULL;
pst = (A*)malloc(sizeof(A)*1);

function1((void*)pst);
}
void function1(void *pStr)
{
// As i need to intialize the structure members. i want to access it's
me
mbers.
// How can i know the structure's
// memory layout in this function?

//Conditions:
//1. i do not want to declare the structure as global or static.
//2. I will pass the structure pointer as void pointer.

}
Back to top
Alf P. Steinbach
Guest





PostPosted: Thu Oct 19, 2006 9:10 am    Post subject: Re: structure's memory layout in the function? Reply with quote



* Narendra:
Quote:
void function1(void *);

Avoid void.


Quote:
void main()

Invalid in C and C++, and has never been valid.


Quote:
{
int size_offset = 0;
typedef struct
{
int a;
int b;
int c;
char ch;
}A;

No need to use a typedef in C++.

Also, reserve all uppercase names for macros.


Quote:

A *pst = NULL;
pst = (A*)malloc(sizeof(A)*1);

Use 'new', not 'malloc'.

Don't use casts.


Quote:
function1((void*)pst);

Don't use casts.


Quote:
}
void function1(void *pStr)
{
// As i need to intialize the structure members. i want to access it's
me
mbers.

Use a constructor to initialize memebers.


Quote:
// How can i know the structure's
// memory layout in this function?

//Conditions:
//1. i do not want to declare the structure as global or static.
//2. I will pass the structure pointer as void pointer.

Since you didn't even get 'main' right, it's doubtful that there are any
good or even meaningful reasons for these conditions.

Quote:

}



--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.