in vga.h I have :
void scroll ( int lines = 1 ) ;
in vga.c I have :
void scroll ( int lines )
{
//implementation
}
GCC gave me the error "Parse error before =" at the line containing the prototype in vga.h .
the only way to correct the error is to delete " = 1 " from prototype , but I want to use default values ,
I am sure that this way was successful in MS visual c++ & borland c++ .
GCC default parameter error
Re:GCC default parameter error
default values for parameters are a feature present in C++, not C.
if you intended to use C++ then you shouldn't give your file a ".c" extention, but either ".C" or ".cpp" or ".cxx"
proxy
if you intended to use C++ then you shouldn't give your file a ".c" extention, but either ".C" or ".cpp" or ".cxx"
proxy
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:GCC default parameter error
Those compilers might have different ways of 'guessing' if some code is C or C++ ... or simply use the C++ compiler for C code aswell ...firas981 wrote: I am sure that this way was successful in MS visual c++ & borland c++ .
If renaming the source files is not an option for you, you may wish to use -x c++ flag in your GCC command line
Re:GCC default parameter error
this is the wrong way to do it...
in vga.h I have :
void scroll ( int lines = 1 ) ;
in vga.c I have :
void scroll ( int lines )
{
//implementation
}
do the following...
the default parameter MUST be given
at the implementation, NOT in the
prototype
in vga.h I have :
void scroll ( int lines ) ;
in vga.c I have :
void scroll ( int lines = 1 )
{
//implementation
}
Re:GCC default parameter error
Cemre, i am sorry but you are mistaken, while it is allowed to have it in the definition and not the prototype, it may be in either but not both. (see http://cplus.about.com/library/weekly/aa061102f.htm).
However, it is better convention to put it in the prototype, here is why.
typically when delivering a library, you deliver a binary source and headers. if the defaults are defined in the source but not the headers, how would the client ever know what the default value is or that there is any at all
proxy
However, it is better convention to put it in the prototype, here is why.
typically when delivering a library, you deliver a binary source and headers. if the defaults are defined in the source but not the headers, how would the client ever know what the default value is or that there is any at all
proxy
Re:GCC default parameter error
Thanks you all , well , I'll continue using c and delete default parameters , but , I want to say that the default parameters
appear only one time ,not more at all . and this "one-time " should be the first time that the function appear which is usually ( but not always) the prototype . I am sure that this is true at least in C++ compilers under Windows that I mentioned before .
and "How to Program in C++" supports my opinion .
Thanks .
appear only one time ,not more at all . and this "one-time " should be the first time that the function appear which is usually ( but not always) the prototype . I am sure that this is true at least in C++ compilers under Windows that I mentioned before .
and "How to Program in C++" supports my opinion .
Thanks .
Re:GCC default parameter error
of course the C++ compilers supports it, like i said it is "a feature of C++ not C"
the problem is that your file is a .c file and any self respecting compiler will default to C mode for that, not C++.
proxy
the problem is that your file is a .c file and any self respecting compiler will default to C mode for that, not C++.
proxy
Re:GCC default parameter error
For which I'm very happy that GCC can be forced to do C++, seeing as I would like my C code to compile with C++-esque name mangling...proxy wrote: the problem is that your file is a .c file and any self respecting compiler will default to C mode for that, not C++.