![]() |
|
#1
|
|||
|
|||
Conflicting typesIn my code i only call method in main.but it shows conflicting types for 'function name' error.why this is occure?
|
|
#2
|
|||
|
|||
Re: conflicting typesQuote:
Whatever you do, don't show the offending code. That might be too helpful for those trying to assist you. The likelihood is that you are invoking a function using the wrong type(s) as (a) parameter(s) to the function. :davis: |
|
#3
|
|||
|
|||
Re: conflicting typesWhat davis means is:
1. You did not post any code for us to be able to see what you were doing wrongly. 2. When using a function declaration in the head area with the actual function following main() you do not need to include the 'data names'... BUT the 'data TYPES' must MATCH EXACTLY. CPP / C++ / C Code:
Howard; |
|
#4
|
|||
|
|||
Re: conflicting typesI have attached my code here.Can u pls help me ?why those conflicting error come?
CPP / C++ / C Code:
Last edited by LuciWiz : 26-Jul-2007 at 13:23.
Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
|
|
#5
|
|||
|
|||
Re: conflicting typesHmmm, in mingw I get the warning:
Code:
I'm not familiar with it. I searched both stdio.h and string.h and found nothing and so assume that index() must come from deep within compilers functions. (hence the 'built-in', duh*) I just changed the name to myindex(). (hope you don't mind since it's really YOUR index*) Another thing is that you didn't have a declaration for the function before main(), like this: CPP / C++ / C Code:
Now it compiles ok..... Outputs nothing... Maybe someone else knows more about the built-in: index() See what a difference it makes when you post your code? Oh, and please DO use the c++ tag icon to enclose code included in your post. Not 'quote' and not 'code' . The tags should say cpp and /cpp, each in square brackets eg: [xxx] your code [/xxx] . Howard; Last edited by Howard_L : 25-Jul-2007 at 23:31.
|
|
#6
|
|||
|
|||
Re: conflicting typesThanks ur reply.now it is work correctly.Thank you very much again
|
|
#7
|
|||
|
|||
Re: conflicting typesQuote:
Quote:
Please don't use 'webspeak'. It doesn't take THAT much longer to write right. At least try. Please read the guidelines. |
|
#8
|
|||
|
|||
Re: conflicting typesQuote:
This is one of those little annoyances that I have with all compilers that I have used from time to time: putting non-standard library function prototypes in standard library headers. There is no standard C library function named index. Never has been (not in our beloved K&R, either). There is, however a "legacy" UNIX function named index (from BSD, I'm thinking, but don't quote me on that). Now, there is a specification of <stdio.h> and a listing of functions therein in both the C89 and C99 standards. My feeling is that if a C compiler vendor supplies any library functions beyond the standard C library functions (for whatever standard they are trying hardest to comply with), that by default they should be not be prototyped in any of the standard library function headers and by default they should not be linked into ordinary user code. I don't know about mingw, but for gcc/cygwin version 3.4.something there is a prototype in <stdio.h> that is surrounded by a conditional #indef __STRICT_ANSI...#endif. So one way to suppress the warning would be to use a command line with the -ansi switch. For gcc 4.something on my Linux systems, there is also a prototype for index in <stdio.h>. It's a little harder to understand what specific conditions are required to use or not use that prototype, but the -ansi switch will suppress the message again. (And with this switch, it will not try to link the built-in index function.) Or you could use either -std=c89 or -std=c99 to get it to compile and link OK. Of course, it's probably easier just to rename the function in the user code, as you did, since the amount of code is so small. My point: From a teaching point of view, I wish all compilers would have their strictest enforcement of ANSI and International Standards in place by default. See footnote. Then, more experienced developers or maintainers of legacy code with non-standard vendor-supplied functions could would use some command-line switch to get the compiler to compile and link these, but the "new guys" would only have to deal with their own stuff, not some old leftover baggage from BSD or whatever. Quote:
But the whole function was defined before main(), so no prototype is required. I always put main() first, for easier editing (I'm funny that way: I like the editor to open at the top of the file, and I like to see main() without scrolling down), so I always have the prototypes at the top (or in a header file if there are lots of them). However, lots of people prefer the other functions first then the main() at the bottom (probably a bunch of old Pascal programmers---or maybe their teachers were). Then, if they put the functions in the right order, they never need prototypes (as long as all of their functions are all in the same compilation unit). Oh, yeah, before I forget: What the heck is the gcc built-in index function? It made it into the POSIX standard (in the "legacy" section). It is specified to be exactly the same as the standard library function strchr! I guess they put it in gcc because some legacy UNIX code uses it (Or, maybe it would be more polite to say that some legacy UNIX programmers wanted to make sure their new open-source code, written with legacy habits, would compile OK with GNU compilers without any pesky command-line switches, so the gcc project mavens put it in. Just guessing, of course.) Regards, Dave Footnote: As another example, Borland has always had functions like "strupr" and "strrev" in their <string.h>, and people learning C with these compilers are surprised and disappointed when they use another compiler and find that these are not available. I personally wish that they (Borland, GNU, Microsoft, etc.) would take all non-standard library functions out of standard library headers and put them somewhere else. Like <conio.h> and <dos.h>: when I see them in a program I know ---and the original programmer knows--- that the program will have some non-standard library functions. It's great when compiler vendors put in extra functions that can be used in any program, but I get tired of arguing with people who say that they have been, "programming for many years and I have always used strupr(). It is in <stdio.h>, so it must be a standard function!" Last edited by davekw7x : 26-Jul-2007 at 10:10.
|
|
#9
|
|||
|
|||
Re: conflicting typesQuote:
I re-searched stdio.h and string.h for the string: 'index', and still find none. They both include a _mingw.h which doesn't have it either. So ...I don't know.... I do see the strchr() in string.h though.... but have never used it. Quote:
Good to think about these facts of C programming. Thanks for the discussion Dave, Howard; Last edited by Howard_L : 26-Jul-2007 at 11:38.
|
Recent GIDBlog
Meeting the local Iraqis by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What are abstract data types | bhagwat_maimt | C++ Forum | 1 | 03-Jan-2007 08:51 |
| Hostall.biz - Quality free hosting for all types of sites! | searche | Web Hosting Advertisements & Offers | 0 | 10-Jul-2006 13:47 |
| Types of Web Site Hosting | Olga Elizarova | Web Hosting Forum | 1 | 15-Mar-2006 14:46 |
| multiple types in one declaration ?! | weeb0 | C++ Forum | 2 | 25-Jan-2006 20:23 |
| Data types and Hardware dependencies | karthikeyansen | C Programming Language | 2 | 03-Apr-2005 21:58 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The