Re: Array setup Question
- From: Artie Gold <artiegold@xxxxxxxxxxxxx>
- Date: Mon, 20 Mar 2006 17:07:25 -0600
Jake Thompson wrote:
HelloAs soon as you say `dll', it's either irrelevant -- or off topic in this newsgroup.
I have the following defined structure
struct cm8linkstruc
{
char *type; /* type of item*/
char *desc; /* description of item */
char *item_increment; /* increment value for item in
folder */
char *itemid; /* id of returned item */
int count; /*total count of array */
};
In the function I have this
struct cm8linkstruc **cm8link;
If I want to allocate 50 occurrences of this array then if the
following correct? It appears to be correct at least at a compile level
because it compiles
/*Allocate the array for use over in the dll */
cm8link = (struct cm8linkstruc **) malloc(50 * sizeof(structBetter:
cm8linkstruc *));
cm8link = malloc(sizeof *cm8link * 50);
Since malloc() returns a pointer to void and such pointer is convertible to any pointer to object the cast is unnecessary -- and should be avoided (it can hide, for example, the failure to include <stdlib.h>.
Further, using the `sizeof object' form is often preferable to the `sizeof(type)' form; it the type happens to be changed, it makes for one less change that need be made...
and, of course, make sure the malloc() succeeded.
for(h = 0; h< 50 ; h++)Better:
{
cm8link[h] = (struct cm8linkstruc *) malloc(sizeof(struct
cm8linkstruc));
cm8link[h] = malloc(sizeof **cm8link);
and, of course, make sure the malloc() succeeded
cm8link[h]->type = 0;
cm8link[h]->desc = 0;
cm8link[h]->item_increment = 0;
cm8link[h]->itemid = 0;
cm8link[h]->count = 0;
}
I have a function in a dll that will add values to the array and then
pass the populated array back to the calling exe
If I am on the right track then would I pass &cm8link to my function in
my dll in order to use it to populate it before I return from the
Again either this `dll' stuff is irrelevant or off topic.
called function?HTH,
--ag
--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com
"You can't KISS* unless you MISS**"
[*-Keep it simple, stupid. **-Make it simple, stupid.]
.
- References:
- Array setup Question
- From: Jake Thompson
- Array setup Question
- Prev by Date: Array setup Question
- Next by Date: Re: Where can I find more about string literals?
- Previous by thread: Array setup Question
- Next by thread: Re: Array setup Question
- Index(es):
Relevant Pages
|