 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Narendra Guest
|
Posted: Thu Oct 19, 2006 9:10 am Post subject: structure's memory layout in the function? |
|
|
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
|
Posted: Thu Oct 19, 2006 9:10 am Post subject: Re: structure's memory layout in the function? |
|
|
* Narendra:
| Quote: | void function1(void *);
|
Avoid void.
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.
--
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 |
|
 |
|
|
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
|
|