User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 401,707 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,979 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Views: 1156 | Replies: 2
Reply
Join Date: Dec 2004
Location: Allentown, PA
Posts: 60
Reputation: murschech is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
murschech murschech is offline Offline
Junior Poster in Training

Forbidden function names in Dev_C++?

  #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.

#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?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2004
Posts: 6,059
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 26
Solved Threads: 419
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: Forbidden function names in Dev_C++?

  #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 a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,693
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 195
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Forbidden function names in Dev_C++?

  #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.
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 8:45 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC