| | |
Forbidden function names in Dev_C++?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2004
Posts: 60
Reputation:
Solved Threads: 1
Calling all Dev_C++ users,
Here's a mystery! The following little program, which determines whether one integer is a divisor of another or not, compiles and runs fine using Borland's bcc32.
When I try compiling it using Dev_C++ I get the message that there's a problem on line 9 because that's the first use of the function "divides". Apparently the compiler is ignoring the function prototype. Now comes the really strange part! If the function name is changed (all three times that it occurs) to almost anything I try, like "divideth" or "fct" or "product" the program works fine, but if I change it to "multiplies" I get the same compilation error.
Can anyone explain this phenomenon?
Here's a mystery! The following little program, which determines whether one integer is a divisor of another or not, compiles and runs fine using Borland's bcc32.
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; bool divides(int,int); main() { int a,b; char ch; cout << "Enter a then b: "; cin >>a>>b; if(divides(a,b)) cout << a << " is a divisor of "<<b<<'\n'; else cout << a << " isn't a divisor of "<<b<<'\n'; cin >> ch; //for dev-c++ } bool divides(int b,int a) { if (!(a%b)) return true; return false; }
When I try compiling it using Dev_C++ I get the message that there's a problem on line 9 because that's the first use of the function "divides". Apparently the compiler is ignoring the function prototype. Now comes the really strange part! If the function name is changed (all three times that it occurs) to almost anything I try, like "divideth" or "fct" or "product" the program works fine, but if I change it to "multiplies" I get the same compilation error.
Can anyone explain this phenomenon?
Borland C++ 5.4 (which ships with BCB4) and 5.5.1 both indeed allow it (both are 6-8 years old by now).
Don't have any others installed here at the moment (VC++ 2005 will go onto this machine in about 2 weeks).
You're indeed most likely getting namespace clashes. Remove the using namespace std; and replace it with explicit namespace references and that may well be gone.
BCC32 has divides in its includes, but it's a template struct taking 3 parameters instead of 2, thus making the function defined in this code sample distinct from the one in the standard library as BCC32 knows it.
Then again, I can't find a reference to <functional> in any of the header files called directly or indirectly by this sample in the headers as supplied by BCC32, so the compiler would never find a clash.
Don't have any others installed here at the moment (VC++ 2005 will go onto this machine in about 2 weeks).
You're indeed most likely getting namespace clashes. Remove the using namespace std; and replace it with explicit namespace references and that may well be gone.
BCC32 has divides in its includes, but it's a template struct taking 3 parameters instead of 2, thus making the function defined in this code sample distinct from the one in the standard library as BCC32 knows it.
Then again, I can't find a reference to <functional> in any of the header files called directly or indirectly by this sample in the headers as supplied by BCC32, so the compiler would never find a clash.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
![]() |
Similar Threads
- Create Access Database using SQL queries (MS Access and FileMaker Pro)
- function style cast question (C++)
- Name of current function.. (Perl)
- what to use to create mobile phone menu?? (Computer Science)
- Old School Compiler vs New Compiler (C++)
- QuickSort (Computer Science)
Other Threads in the C++ Forum
- Previous Thread: Trying to use c++ to print to a usb printer
- Next Thread: Solution for Ex.4-5 in Acc.C++?
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






