From: Igor Tandetnik on
Robby wrote:
> So what if I do this:
>
> typedef struct tag_lb{
> long pmr(*)[5];
> }lb;
>
> would the following assignment work?
>
> lb* LB_create_lb (long pmr[][5])
> {
> lb *obj_lb = NULL;
> obj_lb = (lb*) malloc(sizeof (struct tag_lb));
> obj_lb->pmr = pmr; //<<< Assignment ????

Yes, I believe it should. You can easily determine that experimentally.

>> How do you plan to use this pmr pointer later?
>
> Main would call func1... and do the following:
>
> void func1(lb *pObj, long memOffset, long rm)
> {
> long *p, t;
> p = pObj->pmr;
> t = *(p+(memOffset + rm));

So you basically treat it as a regular flat one-dimensional array. What's the point of all this song and dance around 2d arrays, then?
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
From: Robby on
Hello Igor,

> > So what if I do this:
> >
> > typedef struct tag_lb{
> > long pmr(*)[5];
> > }lb;
> >
> > would the following assignment work?
> >
> > lb* LB_create_lb (long pmr[][5])
> > {
> > lb *obj_lb = NULL;
> > obj_lb = (lb*) malloc(sizeof (struct tag_lb));
> > obj_lb->pmr = pmr; //<<< Assignment ????
>
> Yes, I believe it should. You can easily determine that experimentally.

I tried it but generates errors....Here is what I tried:
===================================
#include <stdio.h>
#include <malloc.h>

typedef struct tag_lb {
long pmr(*)[5];
}lb;

lb* LB_create_lb (long pmr[][5])
{
lb *obj_lb = NULL;
obj_lb = (lb*) malloc(sizeof (struct tag_lb));
obj_lb->pmr = pmr;
return obj_lb;
}

// GLOBAL PROPERTIES MESSAGE RECIPIES
long pmr[5][5] = { 195, 194, 193, 0, 0,
194, 193, 0, 0, 0,
195, 194, 193, 0, 0,
193, 194, 195, 91, 92,
195, 194, 193, 92, 91};

int main()
{
static lb *objLb1 = NULL;
objLb1 = LB_create_lb(pmr);
return 0;
}
================================

here are some of the errors:

1>c:\_dts_programming\pic\_microchip_issues\simulated in
vc++\arrays_2dim\arrays_2dim\arrays_2dim\test2.cpp(8) : error C2059: syntax
error : '*'

1>c:\_dts_programming\pic\_microchip_issues\simulated in
vc++\arrays_2dim\arrays_2dim\arrays_2dim\test2.cpp(8) : error C2090: function
returns array

>these errors point to the following line:

typedef struct tag_lb {
long pmr(*)[5]; <<<<< error points here!
}lb;

and the following error:
1>c:\_dts_programming\pic\_microchip_issues\simulated in
vc++\arrays_2dim\arrays_2dim\arrays_2dim\test2.cpp(15) : error C2659: '=' :
function as left operand

points to this line:
obj_lb->pmr = pmr;


>So you basically treat it as a regular flat one-dimensional array. What's the point >of all this song and dance around 2d arrays, then?

Whats the big deal? Everything can be done in one regular flat single array
too. I can do a program about a rubics cube and assign every square to a
single dimmension array and make sure I offset my data correctly... no? Using
a 2 or 3 dim array further structures your data. So, I figured it would give
a little more structure to my numerical list of 5 numbers each..... and also
gives me a chance to experiment with double dimension arrays. I don't see the
harm in that.

All help appreciated!

Robert

From: Igor Tandetnik on
Robby wrote:
>
> I tried it but generates errors....Here is what I tried:
> ===================================
> #include <stdio.h>
> #include <malloc.h>
>
> typedef struct tag_lb {
> long pmr(*)[5];

long (*pmr)[5];

--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
From: Robby on
> long (*pmr)[5];

wow. I never saw this... but makes sence. Thanks Igor.. I will sure miss
this site when it will close down.

Kindest regards
Roberto
From: Igor Tandetnik on
Robby wrote:
> wow. I never saw this... but makes sence. Thanks Igor.. I will sure miss
> this site when it will close down.

Come on over to

http://social.msdn.microsoft.com/Forums/en-US/vclanguage/threads

(not that I like it any more than you do).
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
First  |  Prev  |  Next  |  Last
Pages: 1 2 3
Prev: Memory allocation
Next: Postfix increment operator?