469,924 Members | 1,419 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,924 developers. It's quick & easy.

macro passed wrong number of arguments

I'm using a matrix and vector library, that won't compile. When
running g++ I get the error message "macro "minor" passed 5 arguments,
but takes just 1"

The definition of "minor" looks like below, and it takes 3 arguments.
All calls to minor that I have found in the code also pass it three
arguments, so I really don't understand this error.

Does anything look suspicious with the following definition, or must
it be that there is some other definition of minor with a different
number of arguments somewhere?

template <int N, typename T>
T minor(const Vector<N,Vector<N,T> >& in, int row, int col) //ERROR
{
Vector<N-1,Vector<N-1,T> > tmp;
int dst_row, dst_col;
dst_row = 0;
for (int src_row = 0; src_row < N; src_row++) {
if (src_row == row) continue;
dst_col = 0;
for (int src_col = 0; src_col < N; src_col++) {
if (src_col == col) continue;
tmp[dst_row][dst_col] = in[src_row][src_col];
dst_col++;
}
dst_row++;
}
return det(tmp);
}

Thanks
/ martin
Jul 22 '05 #1
4 5537

"Martin Magnusson" <lo*******@frustratedhousewives.zzn.com> wrote in message
news:35**************************@posting.google.c om...
I'm using a matrix and vector library, that won't compile. When
running g++ I get the error message "macro "minor" passed 5 arguments,
but takes just 1"

The definition of "minor" looks like below, and it takes 3 arguments.
All calls to minor that I have found in the code also pass it three
arguments, so I really don't understand this error.

Does anything look suspicious with the following definition, or must
it be that there is some other definition of minor with a different
number of arguments somewhere?

template <int N, typename T>
T minor(const Vector<N,Vector<N,T> >& in, int row, int col) //ERROR
{


Yes, somewhere is defined a macro called minor (which takes one argument).
Look at the number of commas on the above line (four of them), therefore the
compiler thinks this is a macro invokation with five arguments.

This is a good example of why macros are evil, *especially* when they are
given common names like minor.

Find out who wrote that macro and shoot them (or at least sack them).

john
Jul 22 '05 #2
John Harrison wrote:
This is a good example of why macros are evil, *especially* when they
are given common names like minor.


And if you really have to write macros, write them (and _nothing_ else)
in all uppercase letters. It reduces the likelyness for name clashes
and it immediately shows that it's a macro.

Jul 22 '05 #3
"John Harrison" <jo*************@hotmail.com> wrote:
Find out who wrote that macro and shoot them (or at least sack them).


I'm using Cygwin, and the file /usr/include/sys/sysmacros.h has the
following definitions:

#ifdef __CYGWIN_USE_BIG_TYPES__
#define major(dev) ((int)(((dev) >> 16) & 0xffff))
#define minor(dev) ((int)((dev) & 0xffff))
#define makedev(major, minor) (((major) << 16) | ((minor) & 0xffff))
#else
#define major(dev) ((int)(((dev) >> 8) & 0xff))
#define minor(dev) ((int)((dev) & 0xff))
#define makedev(major, minor) (((major) << 8) | ((minor) & 0xff))
#endif

So this was the culprit. Weird that the Cygwin developers would define
such macros. (I wonder what they are for).
Jul 22 '05 #4
Martin Magnusson wrote:
"John Harrison" <jo*************@hotmail.com> wrote:
Find out who wrote that macro and shoot them (or at least sack them).

I'm using Cygwin, and the file /usr/include/sys/sysmacros.h has the
following definitions:

#ifdef __CYGWIN_USE_BIG_TYPES__
#define major(dev) ((int)(((dev) >> 16) & 0xffff))
#define minor(dev) ((int)((dev) & 0xffff))
#define makedev(major, minor) (((major) << 16) | ((minor) & 0xffff))
#else
#define major(dev) ((int)(((dev) >> 8) & 0xff))
#define minor(dev) ((int)((dev) & 0xff))
#define makedev(major, minor) (((major) << 8) | ((minor) & 0xff))
#endif

So this was the culprit. Weird that the Cygwin developers would define
such macros. (I wonder what they are for).


They're used for device drivers. In *nix, a device is identified by a
major number and a minor number. In practice, the device number is a
single int. So major and minor are macros that split the dev number out
into its components.

The cygwin guys should have either all capped them (they didn't for
historical reasons), or provided some #ifdef so you could turn them off.
Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

25 posts views Thread by Andrew Dalke | last post: by
1 post views Thread by Martin Magnusson | last post: by
7 posts views Thread by A. Saksena | last post: by
7 posts views Thread by Peter Ammon | last post: by
20 posts views Thread by Srinivas Mudireddy | last post: by
10 posts views Thread by Praveen.Kumar.SP | last post: by
12 posts views Thread by Laurent Deniau | last post: by
5 posts views Thread by martin.brodeur | last post: by
5 posts views Thread by Francois Grieu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.