Skip navigation.
 
mlRe: #define issues
FROM : Michael Rothwell
DATE : Fri Apr 22 04:37:54 2005

More parentheses!

> #define SET_ENTRY( (m),(r),(c),(e)) (m[(r)*4+(c)] = (e))



Michael Rothwell
<email_removed>

On Apr 17, 2005, at 12:47 AM, Cameron Hayne wrote:

On 4/16/05 6:58 AM, "Aaron Boothello" <<email_removed>> wrote:

> typedef double matrix[16];
> #define SET_ENTRY(m,r,c,e) (m[r*4+c] = e)
>
> the 'macro' is called as follows (example):
> SET_ENTRY(ret,1,1,4.5); //where ret is of type matrix
>
> error generated is:incompatible types in assignment.


Well, there is nothing wrong in principle with this code.
I can compile and run the following program with no problem using gcc
3.3:
-------------------------
#include <stdio.h>
typedef double matrix[16];
#define SET_ENTRY(m,r,c,e) (m[r*4+c] = e)
matrix ret;
int main()
{
    SET_ENTRY(ret,1,1,4.5);
    printf("value set was %f\n", ret[5]);
    return 0;
}
-------------------------

So probably your problem is due to something else sneaking in there and
redefining "matrix" or something.
In any case, the standard way to debug a problem with the preprocessor
is to
look at the C code after the preprocessor has done its thing.
E.g. via 'gcc -E'
It is usually obvious what is causing the trouble once you do that.

--
Cameron Hayne (<email_removed>)
Hayne of Tintagel

Related mailsAuthorDate
ml#define issues Aaron Boothello Apr 16, 09:44
mlRe: #define issues Justin Spahr-Summe… Apr 16, 10:09
mlRe: #define issues Aaron Boothello Apr 16, 10:13
mlRe: #define issues p3consulting Apr 16, 10:25
mlRe: #define issues Aaron Boothello Apr 16, 10:35
mlRe: #define issues Justin Spahr-Summe… Apr 16, 11:10
mlRe: #define issues Aaron Boothello Apr 16, 12:58
mlRe: #define issues Cameron Hayne Apr 17, 06:47
mlRe: #define issues Andrew White Apr 18, 05:54
mlRe: #define issues Michael Rothwell Apr 22, 04:37
mlRe: #define issues Steve Checkoway Apr 26, 07:04