|
Are you aware this was your 7000th Message??
Press: 1500 to 2,200 messages in just 6 days? How's that possible sir?
Dr.Brad :Well,I just replied to everything Graus did and then argued with Negus for a bit.
|
|
|
|
|
|
Even I knew it from his link[^]
Press: 1500 to 2,200 messages in just 6 days? How's that possible sir?
Dr.Brad :Well,I just replied to everything Graus did and then argued with Negus for a bit.
|
|
|
|
|
toxcct wrote: Yes[^] :->
:->
|
|
|
|
|
YES! Read the book a few times and LEARN IT. There's alot of new stuff in Windows but the
basics still very much apply. The number of things that have changed or been deprecated is so
small compared to the pain of writing Windows software without understanding the basics.
IMO there's no reason not to use the latest VS/compiler for new application development.
Mark
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
|
Cmania wrote: Although the answer would be VS2005 but wont i be illiterate about VC6 or will it cover that too.
tryhttp://codeproject.com/cpp[^]
|
|
|
|
|
Hello
I want to allocate memory for a void* pointer inside a function;
i tried to do that by using malloc to the pointer passed as an argument ;
the memory space was not kept after function return;
how kan i do that
thanks
|
|
|
|
|
please show a brief piece of the code you wrote for that...
|
|
|
|
|
the code is too long but :
#define STRUCT struct mystruct
void function (void *input){
....
pointer = (STRUCT*) malloc (sizeof(STRUCT));
//filling in input attributes...
input = pointer;
}
main(){
void *ptr;
function (ptr);
printf("%...", ptr->..........);
}
this work only if i allocate the memory for ptr in the main program
|
|
|
|
|
fx9200 wrote: pointer = (STRUCT*) malloc (sizeof(STRUCT));
why don't you directly write into input ?
input = (STRUCT*) malloc (sizeof(STRUCT));
|
|
|
|
|
i tried it
i had the same result in all cases
|
|
|
|
|
Change this to,
void function (void **input){
....
*pointer = (STRUCT*) malloc (sizeof(STRUCT));
input = pointer;
}
main(){
void *ptr;
function (&ptr);
printf("%...", ptr->..........);
}
|
|
|
|
|
fx9200 wrote: the memory space was not kept after function return;
You need to pass your pointer by reference. Otherwise it will still point at the previous memory location.
|
|
|
|
|
how to pass reference(pointer) by reference ?
please give example
|
|
|
|
|
fx9200 wrote: how to pass reference(pointer) by reference ?
please give example
See here.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
he seems to doing C, not C++... so no reference available (in the sense of C++ understands it). but pointers remain good
|
|
|
|
|
yes
so ?
|
|
|
|
|
fx9200 wrote: yes
so ?
so, prasad_som[^] gave you an answer... hve you read it ?
|
|
|
|
|
|
Though, its not applicable in C context. You need to understand theory behind Cedric's suggesstion.
In you original code, you was passing pointer argument. Though its a pointer, it will be passed by value, and inside that function, memory allocated will be not at address you expected.
In that case you need to pass pointer to pointer, as shown in my previous reply.
|
|
|
|
|
but how the code below works;
i allocated memory for chr* inside function
|
|
|
|
|
Which code you are talking about ?
|
|
|
|
|
void fill(void *input);
struct mystruct {
char *ch;
int n;
};
#define ARG_SIZE sizeof(struct mystruct)
int main(){
void *ptr;
ptr = (void*) malloc (ARG_SIZE);
fill(ptr);
printf ("%i",((struct mystruct*)ptr)->n);
printf ("--%s",((struct mystruct*)ptr) ->ch);
return 0;
}
void fill(void *input){
struct mystruct* st;
st = (struct mystruct*) input;
st ->n = 3;//operation is ok
st->ch = (char *) malloc (3*sizeof(char));
strcpy(st->ch,"OK");
input = (void*) st;
}
|
|
|
|
|
Here, though you are allocating memory for ch member of mystruct inside the function, you have passed mystruct* as parameter and , for that memory is already allocated, before calling this function.
And bitwise(shallow) copy happens in this case.
p.s. Dont's create multiple threads for same code.
|
|
|
|