error: function is taken as an micro

M

mohi

hello everyone,

i use a function called minor to find the minor of an element of a
matrix ,
i declare it as :

float minor(float A[ ][COL],int m,int n,int i,int j);//find the minor
in A[][]

and define it later in the file as :


float minor(float A[][COL],int m,int n,int i,int j)
{
if(m==0 ||n==0)//single coloumn or single row
return 1.0;

float temp[ROW][COL];//temp matrix used to find mod (will have one row
and \
//less than the parent matrix
int p,p1,q,q1;//indexes
for(p=0,p1=0;p<=m&& p1<=(m-1);p++,p1++){
if(p==i){
p1--;
continue;//ignore row i
}
for(q=0,q1=0;q<=n && q1<=(n-1);q++,q1++){
if(q==j){
q1--;
continue;//ignore coloumn j
}
temp[p1][q1]=A[p][q];

}
}

float x= mod(temp,m-1,n-1);//return the determinant of temp
return x;
}




when i compile it using gnu g++ it gives the following error :


solve_equation.cpp:13:51: error: macro "minor" passed 5 arguments, but
takes just 1
solve_equation.cpp:68:49: error: macro "minor" passed 5 arguments, but
takes just 1
solve_equation.cpp:76:51: error: macro "minor" passed 5 arguments, but
takes just 1
solve_equation.cpp:121:51: error: macro "minor" passed 5 arguments,
but takes just 1
solve_equation.cpp:76: error: invalid function declaration


as it seems the compiler is taking function minor() as macro .....
but why???
and how is the function declaration invalid??

i use gnu g++ on fedora c8........
thank you

mohan gupta
 
M

mlimber

as it seems the compiler is taking function minor() as macro .....
but why???
and how is the function declaration invalid??

That's not a standard macro; it's something specific to your code,
your system, or third-party libraries. You can #undef it in your
header:

#ifdef minor
# undef minor
#endif

Cheers! --M
 
L

Lionel B

hello everyone,

i use a function called minor to find the minor of an element of a
matrix ,
i declare it as :

float minor(float A[ ][COL],int m,int n,int i,int j);//find the minor in
A[][]
[...]

when i compile it using gnu g++ it gives the following error :


solve_equation.cpp:13:51: error: macro "minor" passed 5 arguments, but
takes just 1
solve_equation.cpp:68:49: error: macro "minor" passed 5 arguments, but
takes just 1
solve_equation.cpp:76:51: error: macro "minor" passed 5 arguments, but
takes just 1
solve_equation.cpp:121:51: error: macro "minor" passed 5 arguments, but
takes just 1
solve_equation.cpp:76: error: invalid function declaration


as it seems the compiler is taking function minor() as macro ..... but
why???

Maybe there really *is* a macro called `minor' defined somewhere? Try
giving your function a different name and see if it compiles. Or insert
some code like:

#ifdef minor
#error macro minor already defined!
#endif

before your function declaration.
and how is the function declaration invalid??

It will be invalid if there is a macro `minor' defined at the point of
declaration, since the preprocessor will substitute the `minor' macro in
your function declaration before the compiler sees it.
 
M

mohi

hello everyone,
i use a function called minor to find the minor of an element of a
matrix ,
i declare it as :
float minor(float A[ ][COL],int m,int n,int i,int j);//find the minor in
A[][]
[...]



when i compile it using gnu g++ it gives the following error :
solve_equation.cpp:13:51: error: macro "minor" passed 5 arguments, but
takes just 1
solve_equation.cpp:68:49: error: macro "minor" passed 5 arguments, but
takes just 1
solve_equation.cpp:76:51: error: macro "minor" passed 5 arguments, but
takes just 1
solve_equation.cpp:121:51: error: macro "minor" passed 5 arguments, but
takes just 1
solve_equation.cpp:76: error: invalid function declaration
as it seems the compiler is taking function minor() as macro ..... but
why???

Maybe there really *is* a macro called `minor' defined somewhere? Try
giving your function a different name and see if it compiles. Or insert
some code like:

#ifdef minor
#error macro minor already defined!
#endif

before your function declaration.
and how is the function declaration invalid??

It will be invalid if there is a macro `minor' defined at the point of
declaration, since the preprocessor will substitute the `minor' macro in
your function declaration before the compiler sees it.

thank you guys ...
that was the real problem that minor was declared as macro
somewhere:::

but i never defined it as an micro and nether am i using any third
party library ,
the starting includes and function declarations of my code are as:



#include<iostream>
#include<cmath>
#include<cstdlib>

using namespace std;

#define ROW 20
#define COL 20


#ifdef minor
#undef minor
#endif

void get_array(float [ROW][COL],int* ,int* );//get the input in array
void inverse(float [][COL],int ,int);//inverse the arary
void multiply(float [][COL],int,int,float [][COL],int,int,float
result[][COL] );//multiply two array
float minor(float A[][COL],int m,int n,int i,int j);//find the minor
in A[][]
float mod(float A[][COL],int m,int n);
void transpose(float temp[][COL],int m,int n,float A[][COL]);//find
trnpos of temp in A
void display(float A[][COL],int m,int n);//display array A[][]
void divide(float array[][COL],int m,int n,float value);//divide
matrix array by
//value

(where i now undefined minor) ,,,,but as i know all the standard
libarray variable are declared with an underscore
say" __micro "(i know that its not an hard and fast rule though) so
where could it have been declared ????can it be in cmath????


thank you
mohan
 
P

peter koch

mohi said:
[..]
(where i now undefined minor) ,,,,but as i know all the standard
libarray variable are declared with an underscore
say" __micro "(i know that its not an hard and fast rule though)   so
where could it have been declared ????can it be in cmath????

Don't ask us.  There *is no* standard macro or function called "minor".
  If you think it's part of your compiler/library package, RTFM.  If you
think it's some third party thing, search the source files and the
headers for 'minor' and examine the output thoroughly.

Compiler implementors and third party library vendors are free to do
what they want.  They are not really obligated to report to you about
the macros they define.  Unfortunately that's the nature of our business
relationship with them.  The easiest work-around for your problem is to
rename your function.

I have to disagree. If compiler implementors were free to #define
anything they wanted, the result would be that portability would be
close to impossible. This is one of the reasons certain names are
reserved for the implementation, and minor is not one of them.
I have not checked my draft of the standard, but it would nor surprise
me, if there was a (perhaps implicit) requirement not to define or use
such names. Anyway, defining such a name is simply bad programming
practice. In normal usercode as well, but especially in a standard
library.

/Peter
 
R

Rolf Magnus

peter said:
mohi said:
[..]
(where i now undefined minor) ,,,,but as i know all the standard
libarray variable are declared with an underscore
say" __micro "(i know that its not an hard and fast rule though)   so
where could it have been declared ????can it be in cmath????

Don't ask us.  There *is no* standard macro or function called "minor".
If you think it's part of your compiler/library package, RTFM.  If you
think it's some third party thing, search the source files and the
headers for 'minor' and examine the output thoroughly.

Compiler implementors and third party library vendors are free to do
what they want.  They are not really obligated to report to you about
the macros they define.  Unfortunately that's the nature of our business
relationship with them.  The easiest work-around for your problem is to
rename your function.

I have to disagree. If compiler implementors were free to #define
anything they wanted, the result would be that portability would be
close to impossible.

Well, they are. Nobody is bringing those compiler writers to jail that don't
obey that rule.
This is one of the reasons certain names are reserved for the
implementation, and minor is not one of them. I have not checked my draft
of the standard, but it would nor surprise me, if there was a (perhaps
implicit) requirement not to define or use such names. Anyway, defining
such a name is simply bad programming practice. In normal usercode as
well, but especially in a standard library.

Maybe the OP didn't use the compiler in ISO C++ mode. Some standard
libraries offer additional functions as extension.
 
P

peter koch

peter said:
mohi wrote:
[..]
(where i now undefined minor) ,,,,but as i know all the standard
libarray variable are declared with an underscore
say" __micro "(i know that its not an hard and fast rule though)   so
where could it have been declared ????can it be in cmath????
Don't ask us.  There *is no* standard macro or function called "minor".
If you think it's part of your compiler/library package, RTFM.  If you
think it's some third party thing, search the source files and the
headers for 'minor' and examine the output thoroughly.
Compiler implementors and third party library vendors are free to do
what they want.  They are not really obligated to report to you about
the macros they define.  Unfortunately that's the nature of our business
relationship with them.  The easiest work-around for your problem is to
rename your function.
I have to disagree. If compiler implementors were free to #define
anything they wanted, the result would be that portability would be
close to impossible.

Well, they are. Nobody is bringing those compiler writers to jail that don't
obey that rule.
This is one of the reasons certain names are reserved for the
implementation, and minor is not one of them. I have not checked my draft
of the standard, but it would nor surprise me, if there was a (perhaps
implicit) requirement not to define or use such names. Anyway, defining
such a name is simply bad programming practice. In normal usercode as
well, but especially in a standard library.

Maybe the OP didn't use the compiler in ISO C++ mode. Some standard
libraries offer additional functions as extension.

This is correct, of course. Still having a #define micro in a C++
standard library is to me an indication of mediocre software
engineering. Still, I know nothing about the compiler and the library,
so perhaps I should watch out?

/Peter
 
L

Lionel B

hello everyone,

i use a function called minor to find the minor of an element of a
matrix, i declare it as :

float minor(float A[ ][COL],int m,int n,int i,int j);//find the minor
in A[][]
[...]
as it seems the compiler is taking function minor() as macro ..... but
why???

Maybe there really *is* a macro called `minor' defined somewhere?

FWIW, you're not the first to be caught out. A quick Google turned up
these, amongst others:

http://www.cpptalk.net/macro-passed-wrong-number-of-arguments-vt35913.html
http://gcc.gnu.org/ml/gcc-help/2004-10/msg00029.html

So its seems (some versions of?) sys/sysmacros.h (part of the GNU C
library on BSD/Linux) define a macro minor. On my system (Gentoo Linux
x86_64) sys/sysmacros.h contains:

/* Access the functions with their traditional names. */
# define major(dev) gnu_dev_major (dev)
# define minor(dev) gnu_dev_minor (dev)
# define makedev(maj, min) gnu_dev_makedev (maj, min)
#endif

Traditional names... hmmm, sounds like a historical thing, then. You'd
have thought at least uppercase names would have been better (and they
perhaps should be undef'ed appropriately in standard headers).
 
R

Rolf Magnus

Lionel said:
FWIW, you're not the first to be caught out. A quick Google turned up
these, amongst others:

http://www.cpptalk.net/macro-passed-wrong-number-of-arguments-vt35913.html
http://gcc.gnu.org/ml/gcc-help/2004-10/msg00029.html

So its seems (some versions of?) sys/sysmacros.h (part of the GNU C
library on BSD/Linux) define a macro minor. On my system (Gentoo Linux
x86_64) sys/sysmacros.h contains:

/* Access the functions with their traditional names. */
# define major(dev) gnu_dev_major (dev)
# define minor(dev) gnu_dev_minor (dev)
# define makedev(maj, min) gnu_dev_makedev (maj, min)
#endif

Traditional names... hmmm, sounds like a historical thing, then. You'd
have thought at least uppercase names would have been better (and they
perhaps should be undef'ed appropriately in standard headers).

They are - if you use the compiler in standard mode. (-ansi or -std=c++98).
 
T

tony_in_da_uk

so where could [macro minor] have been declared ????can it be in cmath????

Your question's already been answered - at least if your Linux
platform does something similar. The general technique though is to
ask your preprocessor or compiler to list the macros in affect - check
the command line switches.

Tony
 
M

mlimber

The #ifdef / #endif are completely unnecessary.  It is perfectly legal
and a preprocessor no-op to #undef a symbol unknown to the
preprocessor.

Right you are. I originally had some preprocessing code to restore the
macro if desired, but then I deleted it and should have deleted the
ifdef, too.

Cheers! --M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top