linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: Returning pointer to array of structures
  2003-04-29  8:31 Returning pointer to array of structures Martin Buchan
@ 2003-04-28 10:57 ` Rafael Santos
  2003-04-30  8:24   ` Martin Buchan
  2003-04-29  9:30 ` Glynn Clements
  2003-04-29 12:11 ` Jason Cooper
  2 siblings, 1 reply; 10+ messages in thread
From: Rafael Santos @ 2003-04-28 10:57 UTC (permalink / raw)
  To: Martin Buchan; +Cc: linux-c-programming

Try the modifications above.


>Hi,
>
>I am trying to populate an array of structures with data read in from an
>xml file (using libxml2). I have a few methods which parse separate chunks
>of the xml file, populate the array, call the next method passing it
>whatever is in the array so far, and then returning the array back to the
>original caller.I am not getting any errors but the array is never
>populated when i return it to the calling function ( and most
>importantly main() ).
>
>Here is my struct and some of my code.
>  
>struct menuentry  
>{
>	char *appsection;
>	char *appsubmenu;
>};
>
>typedef struct menuentry menuentry;
>

- menuentry parseSubmenu (xmlDocPtr doc, xmlNodePtr cur, menuentry *mePtr, int i)
+ void parseSubmenu (xmlDocPtr doc, xmlNodePtr cur, menuentry *mePtr, int i)

>{
>	xmlChar *uri;
>	cur = cur->xmlChildrenNode;
>	printf("I: %d. SECOND SECTION: %s\n", i,  mePtr[i].appsection);
>	while (cur != NULL) 
>	  {
>		  if ((!xmlStrcmp(cur->name, (const xmlChar *)"submenu")))
>			 {
>				 uri = xmlGetProp(cur, "name");
>				 xmlFree(uri);
>				 mePtr[i].appsubmenu = uri;
>				 printf("  SUBMENU: %s\n", mePtr[i].appsubmenu);
>			 }
>		  cur = cur->next;
>	  }

-	return *mePtr;

>}
>

-menuentry parseSection (xmlDocPtr doc, xmlNodePtr cur, menuentry *mePtr)
+void parseSection (xmlDocPtr doc, xmlNodePtr cur, menuentry *mePtr)

>{
>	int i=0;
>	xmlChar *uri;
>	cur = cur->xmlChildrenNode;
>	while (cur != NULL) 
>	  {
>		  if ((!xmlStrcmp(cur->name, (const xmlChar *)"section")))
>			 {
>				   uri = xmlGetProp(cur, "name");
>				   mePtr[i].appsection = uri;
>				   xmlFree(uri);
>				   printf("SECTION: %s\n", mePtr[i].appsection); /*prints out correct */

-				   *mePtr = parseSubmenu(doc, cur, mePtr, i);
+				   parseSubmenu(doc, cur, mePtr, i);

>				   printf("SECOND SUBMENU: %s\n", mePtr[i].appsubmenu); /* empty */
>				   i++;
>			 }
>		  cur = cur->next;
>	  }

-	return *mePtr;

>}
>

-menuentry parseDoc(char *docname, menuentry *mePtr)
+void parseDoc(char *docname, menuentry *mePtr)

>{
>	xmlDocPtr doc;
>	xmlNodePtr cur;
>	doc = xmlParseFile(docname);
>	
>	/* snipped all error checking code */
>	
>	cur = xmlDocGetRootElement(doc);
>	
>	while (cur != NULL) 
>	  {
>		  if ((!xmlStrcmp(cur->name, (const xmlChar *)"root")))
>			 {
>				 printf ("happened once\n");

-				 *mePtr = parseSection (doc, cur, mePtr);
+				 parseSection (doc, cur, mePtr);

>			 }
>		  cur = cur->next;
>	  }
>	xmlFreeDoc(doc);

-	return *mePtr;

>}
>
>int main(int argc, char **argv) 
>{
>	int n = countElements("menuconfig");

-	menuentry *mePtr = malloc( n * sizeof (*mePtr) ); /* Gets size of array */
+	menuentry *mePtr = malloc( n * sizeof (struct menuentry) ); /* Gets size of array */

>	printf ("number of apps: %d\n", n);

-	*mePtr = parseDoc("menuconfig", mePtr); /* calls method to populate me */
+	parseDoc("menuconfig", mePtr); /* calls method to populate me */

>	printf("SECTION: %s\n", mePtr[0].appsection); /* Always empty */
>	return EXIT_SUCCESS;
>}
>
>
>The printf statements in the methods print out the stuff i expect it
>to except for the one that prints out "SECOND SUBMENU:" and also
>the final printf statement in main() shows the array always being
>empty. This tells me i am not returning my pointer properly but i
>cant see what im doing wrong. Can anyone see what i am trying to do
>and/or where the error lies?
>
>Thanks for any help.
>
>Martin
>
>-
>To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
>
Rafael Costa dos Santos
ThinkFreak Comércio e Soluções em Hardware e Software
Rio de Janeiro / RJ / Brazil
rafael@thinkfreak.com.br
+ 55 21 9432-9266


-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Returning pointer to array of structures
@ 2003-04-29  8:31 Martin Buchan
  2003-04-28 10:57 ` Rafael Santos
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Martin Buchan @ 2003-04-29  8:31 UTC (permalink / raw)
  To: linux-c-programming

Hi,

I am trying to populate an array of structures with data read in from an
xml file (using libxml2). I have a few methods which parse separate chunks
of the xml file, populate the array, call the next method passing it
whatever is in the array so far, and then returning the array back to the
original caller.I am not getting any errors but the array is never
populated when i return it to the calling function ( and most
importantly main() ).

Here is my struct and some of my code.
  
struct menuentry  
{
	char *appsection;
	char *appsubmenu;
};

typedef struct menuentry menuentry;

menuentry parseSubmenu (xmlDocPtr doc, xmlNodePtr cur, menuentry *mePtr, int i)
{
	xmlChar *uri;
	cur = cur->xmlChildrenNode;
	printf("I: %d. SECOND SECTION: %s\n", i,  mePtr[i].appsection);
	while (cur != NULL) 
	  {
		  if ((!xmlStrcmp(cur->name, (const xmlChar *)"submenu")))
			 {
				 uri = xmlGetProp(cur, "name");
				 xmlFree(uri);
				 mePtr[i].appsubmenu = uri;
				 printf("  SUBMENU: %s\n", mePtr[i].appsubmenu);
			 }
		  cur = cur->next;
	  }
	return *mePtr;
}

menuentry parseSection (xmlDocPtr doc, xmlNodePtr cur, menuentry *mePtr)
{
	int i=0;
	xmlChar *uri;
	cur = cur->xmlChildrenNode;
	while (cur != NULL) 
	  {
		  if ((!xmlStrcmp(cur->name, (const xmlChar *)"section")))
			 {
				   uri = xmlGetProp(cur, "name");
				   mePtr[i].appsection = uri;
				   xmlFree(uri);
				   printf("SECTION: %s\n", mePtr[i].appsection); /*prints out correct */
				   *mePtr = parseSubmenu(doc, cur, mePtr, i);
				   printf("SECOND SUBMENU: %s\n", mePtr[i].appsubmenu); /* empty */
				   i++;
			 }
		  cur = cur->next;
	  }
	return *mePtr;
}

menuentry parseDoc(char *docname, menuentry *mePtr)
{
	xmlDocPtr doc;
	xmlNodePtr cur;
	doc = xmlParseFile(docname);
	
	/* snipped all error checking code */
	
	cur = xmlDocGetRootElement(doc);
	
	while (cur != NULL) 
	  {
		  if ((!xmlStrcmp(cur->name, (const xmlChar *)"root")))
			 {
				 printf ("happened once\n");
				 *mePtr = parseSection (doc, cur, mePtr);
			 }
		  cur = cur->next;
	  }
	xmlFreeDoc(doc);
	return *mePtr;
}

int main(int argc, char **argv) 
{
	int n = countElements("menuconfig");
	menuentry *mePtr = malloc( n * sizeof (*mePtr) ); /* Gets size of array */
	printf ("number of apps: %d\n", n);
	
	*mePtr = parseDoc("menuconfig", mePtr); /* calls method to populate me */
	printf("SECTION: %s\n", mePtr[0].appsection); /* Always empty */
	return EXIT_SUCCESS;
}


The printf statements in the methods print out the stuff i expect it
to except for the one that prints out "SECOND SUBMENU:" and also
the final printf statement in main() shows the array always being
empty. This tells me i am not returning my pointer properly but i
cant see what im doing wrong. Can anyone see what i am trying to do
and/or where the error lies?

Thanks for any help.

Martin


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Returning pointer to array of structures
  2003-04-29  8:31 Returning pointer to array of structures Martin Buchan
  2003-04-28 10:57 ` Rafael Santos
@ 2003-04-29  9:30 ` Glynn Clements
  2003-04-29 10:28   ` Martin Buchan
  2003-04-29 12:11 ` Jason Cooper
  2 siblings, 1 reply; 10+ messages in thread
From: Glynn Clements @ 2003-04-29  9:30 UTC (permalink / raw)
  To: Martin Buchan; +Cc: linux-c-programming


Martin Buchan wrote:

> I am trying to populate an array of structures with data read in from an
> xml file (using libxml2). I have a few methods which parse separate chunks
> of the xml file, populate the array, call the next method passing it
> whatever is in the array so far, and then returning the array back to the
> original caller.I am not getting any errors but the array is never
> populated when i return it to the calling function ( and most
> importantly main() ).
> 
> Here is my struct and some of my code.

> The printf statements in the methods print out the stuff i expect it
> to except for the one that prints out "SECOND SUBMENU:" and also
> the final printf statement in main() shows the array always being
> empty. This tells me i am not returning my pointer properly but i
> cant see what im doing wrong. Can anyone see what i am trying to do
> and/or where the error lies?

You aren't returning a pointer, you're returning a structure. 
Moreover:

a) you always return the first element of the array (*mePtr is
equivalent to mePtr[0]), and

b) you always store the returned structure in the first element of the
array.

This isn't an error in itself, but the overall structure of the code
means that you are effectively doing:

	mePtr[0] = mePtr[0];

repeatedly. As this is redundant, it seems likely that you meant to do
something else.

I'm not familiar with libxml2, so I can't comment on that aspect of
it. But that's probably irrelevant; your problem seems to be a
fundamental misunderstanding about the nature of pointers and arrays.

Maybe you should try taking a small section of code, and explaining
what you think it does.

OTOH, this is almost certainly an error:

	 uri = xmlGetProp(cur, "name");
	 xmlFree(uri);
	 mePtr[i].appsubmenu = uri;

Assuming that xmlFree() is a "destructor", you shouldn't be calling it
until you have actually finished with "uri". Given that you are
storing "uri" for later use, you probably either shouldn't be calling
xmlFree() at all, or you should be copying the string itself (e.g. 
with strdup()), and not just the pointer.

-- 
Glynn Clements <glynn.clements@virgin.net>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Returning pointer to array of structures
  2003-04-29  9:30 ` Glynn Clements
@ 2003-04-29 10:28   ` Martin Buchan
  0 siblings, 0 replies; 10+ messages in thread
From: Martin Buchan @ 2003-04-29 10:28 UTC (permalink / raw)
  To: Glynn Clements; +Cc: linux-c-programming

On Tue, Apr 29, 2003 at 10:30:34AM +0100, Glynn Clements wrote:
> 
> OTOH, this is almost certainly an error:
> 
> 	 uri = xmlGetProp(cur, "name");
> 	 xmlFree(uri);
> 	 mePtr[i].appsubmenu = uri;
> 
> Assuming that xmlFree() is a "destructor", you shouldn't be calling it
> until you have actually finished with "uri". Given that you are
> storing "uri" for later use, you probably either shouldn't be calling
> xmlFree() at all, or you should be copying the string itself (e.g. 
> with strdup()), and not just the pointer.

Thanks! This was the error. I have used strdup() as you sugessted and
now it all seems to be working. My structure is returned to main()
successfully and i can print out each element using a for loop.

Thanks again for your help.

Martin

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Returning pointer to array of structures
  2003-04-29  8:31 Returning pointer to array of structures Martin Buchan
  2003-04-28 10:57 ` Rafael Santos
  2003-04-29  9:30 ` Glynn Clements
@ 2003-04-29 12:11 ` Jason Cooper
  2003-04-29 20:57   ` Glynn Clements
  2 siblings, 1 reply; 10+ messages in thread
From: Jason Cooper @ 2003-04-29 12:11 UTC (permalink / raw)
  To: linux-c-programming

Martin Buchan (M.J.Buchan@gre.ac.uk) wrote:
> Hi,
> 
> I am trying to populate an array of structures with data read in from an
> xml file (using libxml2). I have a few methods which parse separate chunks
> of the xml file, populate the array, call the next method passing it
> whatever is in the array so far, and then returning the array back to the
> original caller.I am not getting any errors but the array is never
> populated when i return it to the calling function ( and most
> importantly main() ).
> 
> Here is my struct and some of my code.
>   
> struct menuentry  
> {
> 	char *appsection;
> 	char *appsubmenu;
> };
> 
> typedef struct menuentry menuentry;
> 
> menuentry parseSubmenu (xmlDocPtr doc, xmlNodePtr cur, menuentry *mePtr, int i)
> {
> 	xmlChar *uri;
> 	cur = cur->xmlChildrenNode;
> 	printf("I: %d. SECOND SECTION: %s\n", i,  mePtr[i].appsection);
> 	while (cur != NULL) 
> 	  {
> 		  if ((!xmlStrcmp(cur->name, (const xmlChar *)"submenu")))
> 			 {
> 				 uri = xmlGetProp(cur, "name");
> 				 xmlFree(uri);
> 				 mePtr[i].appsubmenu = uri;
> 				 printf("  SUBMENU: %s\n", mePtr[i].appsubmenu);
> 			 }
> 		  cur = cur->next;
> 	  }
> 	return *mePtr;
> }


Hey, I am by no means an expert, but at my new job (1.5 months) I've
just had a crash course in this for the project I'm on (C coding on
linux).  With that in mind, here is what I see:

1.) Your pointer *mePtr is being passed as an argument.  It does not
need to be returned.  Your local function will modify the memory space
that *mePtr points to.  

2.) mePtr[i] doesn't make sense.  It's equivalent to adding the size of
struct menuentry to the address mePtr contains ( if i=1, eg).  Not to
mention that it was never declared as an array in the first place.  I
think you may be confusing char */array ([1] increments one byte) with
pointers of different types.

3.) With malloc, it should probably be 

menuentry *mePtr;
mePtr = malloc(n * sizeof(struct menuentry));
...
free(mePtr);
return...

4.) Consider this (without malloc/free)):

int main(yada yada) {
   menuentry me[MAXENTRIES];

   n = countElements();

   for(i = 0; i < n; i++) {

      func_call(fnjsf, fdo, &me[i]);

   }

}
int func_call(int a, int b, menuentry *me) {

...

   return 0; /*success*/
}


Like I said above, I haven't been doing this too long, so I may be
wrong.  I don't mean to sound harsh, but it look as though you could use
a crash course in pointers, arrays, and malloc/free.  Don't take it the
wrong way, I just learned it the hard way a month ago myself.

HTH,

Cooper.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Returning pointer to array of structures
  2003-04-29 12:11 ` Jason Cooper
@ 2003-04-29 20:57   ` Glynn Clements
  0 siblings, 0 replies; 10+ messages in thread
From: Glynn Clements @ 2003-04-29 20:57 UTC (permalink / raw)
  To: Jason Cooper; +Cc: linux-c-programming


Jason Cooper wrote:

> 1.) Your pointer *mePtr is being passed as an argument.

Just to be picky: "mePtr" is a pointer; "*mePtr" is what mePtr points
to, i.e. a structure; it's equivalent to mePtr[0].

> It does not
> need to be returned.  Your local function will modify the memory space
> that *mePtr points to.  

This is correct.

> 2.) mePtr[i] doesn't make sense.

Sure it does; it's the i-th element of the array to which mePtr
points.

> It's equivalent to adding the size of
> struct menuentry to the address mePtr contains ( if i=1, eg).

Yes; this is just array access. BTW, the following are all equivalent:

	mePtr[i]
	*(mePtr + i)
	*(i + mePtr)
	i[mePtr]

However, using the last form isn't recommended if you want other
people to understand your code.

> Not to
> mention that it was never declared as an array in the first place.

It was declared as:

	menuentry *mePtr = malloc( n * sizeof (*mePtr) ); /* Gets size of array */

IOW, it points to an array of n menuentry structures.

In C, arrays are passed by reference; IOW, wherever you treat an array
as a value, the value is actually the pointer to the first element. 
So, array accesses (array[index]) actually operate upon pointers
rather than arrays.

The only place where an array is actually treated as an array (rather
than a pointer) is when passed to sizeof.

> I
> think you may be confusing char */array ([1] increments one byte) with
> pointers of different types.

No; mePtr[i] is correct.

> 3.) With malloc, it should probably be 
> 
> menuentry *mePtr;
> mePtr = malloc(n * sizeof(struct menuentry));
> ...
> free(mePtr);
> return...

The argument to sizeof can be either a type or a value. As the type of
"*mePtr" is "menuentry", and "menuentry" is just an alias (typedef)
for "struct menuentry", all of the following are equivalent:

	sizeof(*mePtr)
	sizeof(menuentry)
	sizeof(struct menuentry)

> 4.) Consider this (without malloc/free)):
> 
> int main(yada yada) {
>    menuentry me[MAXENTRIES];

This requires that the number of entries is known at compile time. If
the number of entries isn't known until run time, the memory has to be
allocated dynamically, e.g. with malloc().

> Like I said above, I haven't been doing this too long, so I may be
> wrong.  I don't mean to sound harsh, but it look as though you could use
> a crash course in pointers, arrays, and malloc/free.

He isn't the only one ;)

> Don't take it the
> wrong way, I just learned it the hard way a month ago myself.

I've been doing C for ~15 years, so I think I have the pointer/array
issues figured out by now. But I had been (intermittently) using
assembly language for ~10 years before learning C, and that helps.

-- 
Glynn Clements <glynn.clements@virgin.net>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Returning pointer to array of structures
  2003-04-28 10:57 ` Rafael Santos
@ 2003-04-30  8:24   ` Martin Buchan
  2003-05-01  0:49     ` Glynn Clements
  0 siblings, 1 reply; 10+ messages in thread
From: Martin Buchan @ 2003-04-30  8:24 UTC (permalink / raw)
  To: Rafael Santos; +Cc: linux-c-programming

Hi,

On Mon, Apr 28, 2003 at 07:57:07AM -0300, Rafael Santos wrote:
> Try the modifications above.
>
> - menuentry parseSubmenu (xmlDocPtr doc, xmlNodePtr cur, menuentry *mePtr, int i)
> + void parseSubmenu (xmlDocPtr doc, xmlNodePtr cur, menuentry *mePtr, int i)

Thanks. Ive done as you suggested and it all works. 

As the way i had coded it before where i was returning the structure
each time worked, I am assuming this is a better way to code it (seeing 
as you guys have suggested it and i know diddly squat :-)

Why is this so?
Is it just because i do not have the extra overhead of
passing/returning the structure for each function call or is there
something more fundamental?

Excuse my ignorance but this is my first C program after hello world
:-)

Thanks again.

Martin

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Returning pointer to array of structures
  2003-04-30  8:24   ` Martin Buchan
@ 2003-05-01  0:49     ` Glynn Clements
  2003-05-01  6:03       ` Rafael Santos
  2003-05-01  9:49       ` Martin Buchan
  0 siblings, 2 replies; 10+ messages in thread
From: Glynn Clements @ 2003-05-01  0:49 UTC (permalink / raw)
  To: Martin Buchan; +Cc: linux-c-programming


Martin Buchan wrote:

> > Try the modifications above.
> >
> > - menuentry parseSubmenu (xmlDocPtr doc, xmlNodePtr cur, menuentry *mePtr, int i)
> > + void parseSubmenu (xmlDocPtr doc, xmlNodePtr cur, menuentry *mePtr, int i)
> 
> Thanks. Ive done as you suggested and it all works. 
> 
> As the way i had coded it before where i was returning the structure
> each time worked, I am assuming this is a better way to code it (seeing 
> as you guys have suggested it and i know diddly squat :-)
> 
> Why is this so?
> Is it just because i do not have the extra overhead of
> passing/returning the structure for each function call or is there
> something more fundamental?

The main issue is that it's unnecessary in this case. That lead me
(and probably others) to suspect that you might have misunderstood
what was happening and/or meant to do something else.

E.g. parseSection() calls parseSubmenu(), passing mePtr as an
argument. parseSubmenu() stores data in the elements of mePtr, and
also returns the first element (*mePtr, equivalent to mePtr[0]) as a
result. parseSection() then stores the result in *mePtr, even though
the value it's storing is bound to be exactly what's already there.

In general, there are two ways to return values from a function:

1. Return the value as the function's result.

2. Pass in a pointer to where you want the value to be stored, and
have the function store it there.

Option 2 is normally chosen if you want to return:

a) multiple values,
b) an array, or
c) large structures.

Option 1 is normally chosen if you only want to return a single, small
value (usually a primitive type such as int, float etc).

Case a) is due to C functions only being able return a single value. 
Case b) is because arrays are always passed by reference (a pointer to
the first element of the array). Case c) is for efficiency; returning
a result typically involves the callee copying it onto the stack, then
the caller copying it from the stack.

-- 
Glynn Clements <glynn.clements@virgin.net>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Returning pointer to array of structures
  2003-05-01  0:49     ` Glynn Clements
@ 2003-05-01  6:03       ` Rafael Santos
  2003-05-01  9:49       ` Martin Buchan
  1 sibling, 0 replies; 10+ messages in thread
From: Rafael Santos @ 2003-05-01  6:03 UTC (permalink / raw)
  To: Glynn Clements; +Cc: linux-c-programming

Excelente explanation.... Totally Agreed
Better than just fixing as I have done.

Great.


4/30/03 9:49:21 PM, Glynn Clements <glynn.clements@virgin.net> wrote:

>
>Martin Buchan wrote:
>
>> > Try the modifications above.
>> >
>> > - menuentry parseSubmenu (xmlDocPtr doc, xmlNodePtr cur, menuentry *mePtr, int i)
>> > + void parseSubmenu (xmlDocPtr doc, xmlNodePtr cur, menuentry *mePtr, int i)
>> 
>> Thanks. Ive done as you suggested and it all works. 
>> 
>> As the way i had coded it before where i was returning the structure
>> each time worked, I am assuming this is a better way to code it (seeing 
>> as you guys have suggested it and i know diddly squat :-)
>> 
>> Why is this so?
>> Is it just because i do not have the extra overhead of
>> passing/returning the structure for each function call or is there
>> something more fundamental?
>
>The main issue is that it's unnecessary in this case. That lead me
>(and probably others) to suspect that you might have misunderstood
>what was happening and/or meant to do something else.
>
>E.g. parseSection() calls parseSubmenu(), passing mePtr as an
>argument. parseSubmenu() stores data in the elements of mePtr, and
>also returns the first element (*mePtr, equivalent to mePtr[0]) as a
>result. parseSection() then stores the result in *mePtr, even though
>the value it's storing is bound to be exactly what's already there.
>
>In general, there are two ways to return values from a function:
>
>1. Return the value as the function's result.
>
>2. Pass in a pointer to where you want the value to be stored, and
>have the function store it there.
>
>Option 2 is normally chosen if you want to return:
>
>a) multiple values,
>b) an array, or
>c) large structures.
>
>Option 1 is normally chosen if you only want to return a single, small
>value (usually a primitive type such as int, float etc).
>
>Case a) is due to C functions only being able return a single value. 
>Case b) is because arrays are always passed by reference (a pointer to
>the first element of the array). Case c) is for efficiency; returning
>a result typically involves the callee copying it onto the stack, then
>the caller copying it from the stack.
>
>-- 
>Glynn Clements <glynn.clements@virgin.net>
>-
>To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
>
Rafael Costa dos Santos
ThinkFreak Comércio e Soluções em Hardware e Software
Rio de Janeiro / RJ / Brazil
rafael@thinkfreak.com.br
+ 55 21 9432-9266


-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Returning pointer to array of structures
  2003-05-01  0:49     ` Glynn Clements
  2003-05-01  6:03       ` Rafael Santos
@ 2003-05-01  9:49       ` Martin Buchan
  1 sibling, 0 replies; 10+ messages in thread
From: Martin Buchan @ 2003-05-01  9:49 UTC (permalink / raw)
  To: Glynn Clements; +Cc: linux-c-programming

On Thu, May 01, 2003 at 01:49:21AM +0100, Glynn Clements wrote:
> > 
> > As the way i had coded it before where i was returning the structure
> > each time worked, I am assuming this is a better way to code it (seeing 
> > as you guys have suggested it and i know diddly squat :-)
> > 
> > Why is this so?
> 
> The main issue is that it's unnecessary in this case. That lead me
> (and probably others) to suspect that you might have misunderstood
> what was happening and/or meant to do something else.

Yep. :-)

I think i have a better understanding now though and am very
grateful to the list for sorting me out, as i have also been thrown
into C programming by my boss. 

arrghh, bring back Perl!

Thanks again.

Martin

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2003-05-01  9:49 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-04-29  8:31 Returning pointer to array of structures Martin Buchan
2003-04-28 10:57 ` Rafael Santos
2003-04-30  8:24   ` Martin Buchan
2003-05-01  0:49     ` Glynn Clements
2003-05-01  6:03       ` Rafael Santos
2003-05-01  9:49       ` Martin Buchan
2003-04-29  9:30 ` Glynn Clements
2003-04-29 10:28   ` Martin Buchan
2003-04-29 12:11 ` Jason Cooper
2003-04-29 20:57   ` Glynn Clements

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).