Forbidden function names in Dev_C++?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2004
Posts: 60
Reputation: murschech is an unknown quantity at this point 
Solved Threads: 1
murschech murschech is offline Offline
Junior Poster in Training

Forbidden function names in Dev_C++?

 
0
  #1
Feb 10th, 2006
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.

  1. #include <iostream>
  2. using namespace std;
  3. bool divides(int,int);
  4.  
  5. main()
  6. { int a,b;
  7. char ch;
  8. cout << "Enter a then b: ";
  9. cin >>a>>b;
  10. if(divides(a,b))
  11. cout << a << " is a divisor of "<<b<<'\n';
  12. else
  13. cout << a << " isn't a divisor of "<<b<<'\n';
  14. cin >> ch; //for dev-c++
  15.  
  16. }
  17.  
  18. bool divides(int b,int a)
  19. { if (!(a%b))
  20. return true;
  21. return false;
  22. }

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?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,603
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 713
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Forbidden function names in Dev_C++?

 
0
  #2
Feb 10th, 2006
divides is a standard function object defined in <functional>, and Dev-C++ is better at not letting you do stupid things than the older Borland C++ 5.5 (which is what I assume you're using).
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Forbidden function names in Dev_C++?

 
0
  #3
Feb 11th, 2006
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC