G
Garry Freemyer
I'm trying to convert this macro to a c# function but I have a big problem.
It's on the LEFT side of an assignment statement and I am extremely
flustered over this one because I'm a little rusty and have been struggling
over this for days, not wanting to show all my ignorance in final desparate
plea for help which this is ...
Here is the macro ...
#define X(t,b) (sp->x[(t)*sp->beecount+(b)])
sp is a pointer to a structure like this
typedef struct {
int beecount; // beecount is set to 144
int *x // is set to a random pixel X location.
} swarmstruct
x is allocated memory thusly ...
sp->x = (short *) malloc(sizeof(short) * sp->beecount * TIMES); // TIMES is
a constant = 4
Later, X is called like this ..
for (b = 0; b < sp->beecount; b++) {
X(0,b) = rand() % width; // width is the screen width.
X(1, b) = X(0, b);
}
What confuses me is that when I try to translate this I get the following
for the first call ...
sp->x[(0)*sp->beecount+(0)]
I am confused by this. If I take this * operator as meaning the indirection
operator than what does the (0) I get what appears to make no sense to me
.... x[(0)MemLoc(beecount)+0] = a random pixal x location and am trying to
assign a number to an address and treating an address as an indexor?
If I take the * to mean multiply than I am doing x[0 * sp->beecount + b] =
random pixal x location but that is so redundant because it just comes down
to x = something.
I am equally confused by the second call which to me looks like it should
create an overflow error.
I do not understand what is happening here. There is no real meaningful
documentation and the author allows the inclusion of the source code as long
as I mention his name in the ending program.
I would have put this in the C++ forum here but there ISN'T one, and I'm
trying to convert it to c# using arrays instead of pointers and I'm stuck
bigtime on this point.
Anyone have any hints as to how I should convert or interprety this macro?
I've been trying to interpret it by simply doing the pre-processing inlining
by hand since c# has no macro ability but since the macros use pointers and
I'm trying to convert to array logic, I haven't a hope of interpreting this
until I understand what X is supposed to do.
Thanks for any help. /hangs my head in shame of his ignorance.
It's on the LEFT side of an assignment statement and I am extremely
flustered over this one because I'm a little rusty and have been struggling
over this for days, not wanting to show all my ignorance in final desparate
plea for help which this is ...
Here is the macro ...
#define X(t,b) (sp->x[(t)*sp->beecount+(b)])
sp is a pointer to a structure like this
typedef struct {
int beecount; // beecount is set to 144
int *x // is set to a random pixel X location.
} swarmstruct
x is allocated memory thusly ...
sp->x = (short *) malloc(sizeof(short) * sp->beecount * TIMES); // TIMES is
a constant = 4
Later, X is called like this ..
for (b = 0; b < sp->beecount; b++) {
X(0,b) = rand() % width; // width is the screen width.
X(1, b) = X(0, b);
}
What confuses me is that when I try to translate this I get the following
for the first call ...
sp->x[(0)*sp->beecount+(0)]
I am confused by this. If I take this * operator as meaning the indirection
operator than what does the (0) I get what appears to make no sense to me
.... x[(0)MemLoc(beecount)+0] = a random pixal x location and am trying to
assign a number to an address and treating an address as an indexor?
If I take the * to mean multiply than I am doing x[0 * sp->beecount + b] =
random pixal x location but that is so redundant because it just comes down
to x = something.
I am equally confused by the second call which to me looks like it should
create an overflow error.
I do not understand what is happening here. There is no real meaningful
documentation and the author allows the inclusion of the source code as long
as I mention his name in the ending program.
I would have put this in the C++ forum here but there ISN'T one, and I'm
trying to convert it to c# using arrays instead of pointers and I'm stuck
bigtime on this point.
Anyone have any hints as to how I should convert or interprety this macro?
I've been trying to interpret it by simply doing the pre-processing inlining
by hand since c# has no macro ability but since the macros use pointers and
I'm trying to convert to array logic, I haven't a hope of interpreting this
until I understand what X is supposed to do.
Thanks for any help. /hangs my head in shame of his ignorance.