[Bug c/33219] New: Error in compiling when there is a function with a char parameter called before its declaration with inline parameters.
-- Summary: Error in compiling when there is a function with a char parameter called before its declaration with inline parameters. Product: gcc Version: 4.1.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: andreagrassi at sogeasoft dot com GCC host triplet: Linux Sles 10 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33219
[Bug c/33219] Error in compiling when there is a function with a char parameter called before its declaration with inline parameters.
--- Comment #1 from andreagrassi at sogeasoft dot com 2007-08-28 15:24 --- Created an attachment (id=14126) --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=14126&action=view) Source -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33219
[Bug c/33219] Error in compiling when there is a function with a char parameter called before its declaration with inline parameters.
--- Comment #2 from andreagrassi at sogeasoft dot com 2007-08-28 15:25 --- Created an attachment (id=14127) --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=14127&action=view) preprocessed file -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33219
[Bug c/33219] Error in compiling when there is a function with a char parameter called before its declaration with inline parameters.
--- Comment #3 from andreagrassi at sogeasoft dot com 2007-08-28 15:42 --- Sorry I confirmed for mistake ... Continue the bug report... The code is very simple and you can read it in the souce code a.c. Command line of the compile is simple too: "gcc a.c". * Error message: "a.c:7: error: conflicting types for 'a' a.c:7: note: an argument type that has a default promotion can't match an empty parameter name list declaration a.c:3: error: previous implicit declaration of 'a' was here a.c: In function 'a': a.c:8: warning: incompatible implicit declaration of built-in function 'printf'" * Condition of the error: 1) Function with at least a parameter declared as "char". 2) Function called before its declaration 3) Inline parameter list declaration (that is with the types declared inside the parenthesis. In fact, If one of the previous conditions miss, the source is compiled with success. If for example, the declaration was " a(a) char a; { " the compiling works, whereas if I write " a(char a) " it fails. -- andreagrassi at sogeasoft dot com changed: What|Removed |Added Severity|normal |enhancement http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33219
[Bug c/33219] Error in compiling when there is a function with a char parameter called before its declaration with inline parameters.
--- Comment #5 from andreagrassi at sogeasoft dot com 2007-08-28 16:50 --- Subject: R: Error in compiling when there is a function with a char parameter called before its declaration with inline parameters. Yes and the error remains. Nothing changes. I don't understand the error !! It's all so simple and I don't understand why the compile works if I write in the second form (not inline parameter declaration) !!! Le informazioni contenute in questo messaggio di posta elettronica sono di natura confidenziale; qualsiasi pubblicazione, utilizzo o diffusione anche parziale dello stesso non può essere effettuata senza autorizzazione e potrebbe costituire un illecito penale ai sensi del Decreto Legs.vo N° 196/2003 sulla Protezione dei Dati Personali e del Codice Penale, Art. 617-621-635 bis oltre che della legge 547/93. Qualora non siate tra i legittimi destinatari di questa e-mail Vi preghiamo cortesemente di cancellarla dal Vostro sistema dopo aver notificato al mittente, rispondendo alla comunicazione, l'errore da questi commesso. > -Messaggio originale- > Da: pcarlini at suse dot de [mailto:[EMAIL PROTECTED] > Inviato: martedì 28 agosto 2007 17.57 > A: [EMAIL PROTECTED] > Oggetto: [Bug c/33219] Error in compiling when there is a > function with > a char parameter called before its declaration with inline parameters. > > > > > --- Comment #4 from pcarlini at suse dot de 2007-08-28 > 15:56 --- > Out of curiosity, do you ever add -Wall to the command line? > > > -- > > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33219 > > --- You are receiving this mail because: --- > You reported the bug, or are watching the reporter. > > > > -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33219
[Bug c/33219] Error in compiling when there is a function with a char parameter called before its declaration with inline parameters.
-- andreagrassi at sogeasoft dot com changed: What|Removed |Added Severity|enhancement |major http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33219
[Bug c/33219] Error in compiling when there is a function with a char parameter called before its declaration with inline parameters.
--- Comment #7 from andreagrassi at sogeasoft dot com 2007-08-29 13:56 --- Subject: R: Error in compiling when there is a function with a char parameter called before its declaration with inline parameters. Thank you so much for the speed, the kindness and the precision with which you answered me but I continue to think this is a gcc programmers mistake or , at least, it shouldn't work so. 1. First, you spoke about an internal difference between the "inline" and "not inline" definition, but in my opinion this should be only a syntax difference and not a semanthics one. In other words my two codes should be only formally different but with the same meaning. 2. Then, I understand that the compiler at the compile-time must understand the type of a value and so it promotes this value to the larger type it can include this value but then it should be able to re-cast the type to the new type in the definition if there is compatibility between the two types. (In this case between "int" and "char" there is full compatibility !!) I know that re-casting an "int" to "char" I could have loss or alteration of data because it pass from a larger to a smaller one but usually the C permits this. -You can think to the assignemt. The following code is allowed: char c; int i=0; c=i; // <--- implicit conversion from larger to smaller!!! Syntactically good code -The pointer are accepted even if they belong to different type pointers. This following code is syntactically permited even if it's full of type errors that probably will make my code fail !! main() { double a; ffa(&a); // < *double } // | // | ffa(int *par) // < *int { char c; printf("%c\n",*par); // char <--> int return(0); } - ecc... So a warning is correct (more, needed ) but not an error !!! 3. In the prevoius version (3.x) of gcc this was OK.!! 4. Consider the error message: "an argument type that has a default promotion can't match an empty parameter name list declaration" empty parameter ? Where it saw this ? The message is wrong ... This make me suspect that the compiler goes in an not managed case of failure !! In fact if I read your "c-decl.c" code in the function "diagnose_mismatched_decls()", the message "conflicting types for..." is the LAST branch of the "if/then/elsif/../elsif/else" case !! And the following line with "diagnose_arglist_conflict()" find a wrong message/note because probably this failure was not desired and considered. Sorry if I bored with this long mail, but I try to explain to you the reason for which I think this should be considered a bug. I know the problem is by-passable but I have a lot of sources with this new errors and this would make me to adjust all these codes. Please let me know if this can be considered a bug and if / when you think to solve and fix it. Thank you so much anyway. Best regards. Andrea > -Messaggio originale- > Da: raeburn at raeburn dot org [mailto:[EMAIL PROTECTED] > Inviato: mercoledì 29 agosto 2007 13.13 > A: [EMAIL PROTECTED] > Oggetto: [Bug c/33219] Error in compiling when there is a > function with > a char parameter called before its declaration with inline parameters. > > > > > --- Comment #6 from raeburn at raeburn dot org > 2007-08-29 11:12 --- > (In reply to comment #5) > > I don't understand the error !! It's all so simple and I > don't understand > > why the compile works if I write in the second form (not > inline parameter > > declaration) !!! > > (This would be more suitable for the gcc-help list, btw...) > > The bit about a type with default promotions refers to the > fact that if there > isn't a prototype declaration (or a prototype style function > definition) in > scope for the function, then integral arguments narrower than > "int" get > "promoted" to "int" in the function signature, and that's how > the argument gets > passed. (And "float" would become "double" as well.) Your > second ("not > inline") version uses a non-prototype style definition, so > the passed argument > type is in fact an "int". > > In the first version of your code, the function is called > with no declaration > in scope, so it's assumed that all argument types are the > result of the default > promotions, and then you declare it as taking a "char" not > promoted to "int", > which conflicts with the previous assumption. > > (The use of a function without a prot
[Bug c/33219] Error in compiling when there is a function with a char parameter called before its declaration with inline parameters.
--- Comment #10 from andreagrassi at sogeasoft dot com 2007-08-29 17:01 --- Subject: R: Error in compiling when there is a function with a char parameter called before its declaration with inline parameters. Read again your "brilliant" error message where you mention why my code is invalid (even was invalid) !! My parameter name list declaration is not empty !! Maybe don't match the promoted type but not is empty. At least fix the message ... Le informazioni contenute in questo messaggio di posta elettronica sono di natura confidenziale; qualsiasi pubblicazione, utilizzo o diffusione anche parziale dello stesso non può essere effettuata senza autorizzazione e potrebbe costituire un illecito penale ai sensi del Decreto Legs.vo N° 196/2003 sulla Protezione dei Dati Personali e del Codice Penale, Art. 617-621-635 bis oltre che della legge 547/93. Qualora non siate tra i legittimi destinatari di questa e-mail Vi preghiamo cortesemente di cancellarla dal Vostro sistema dopo aver notificato al mittente, rispondendo alla comunicazione, l'errore da questi commesso. > -Messaggio originale- > Da: pinskia at gcc dot gnu dot org [mailto:[EMAIL PROTECTED] > Inviato: mercoledì 29 agosto 2007 18.16 > A: [EMAIL PROTECTED] > Oggetto: [Bug c/33219] Error in compiling when there is a > function with > a char parameter called before its declaration with inline parameters. > > > > > --- Comment #8 from pinskia at gcc dot gnu dot org > 2007-08-29 16:15 --- > No C is defined this way. Look at the error message, we > mention why this code > is invalid. > > a.c:7: note: an argument type that has a default promotion > can't match an empty > > parameter name list declaration > > What more do you want from GCC, except from accepting this > invalid code? > > > -- > > pinskia at gcc dot gnu dot org changed: > >What|Removed |Added > -- > -- > Status|UNCONFIRMED |RESOLVED > Resolution||INVALID > > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33219 > > --- You are receiving this mail because: --- > You reported the bug, or are watching the reporter. > > > > -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33219
[Bug c/33219] Error in compiling when there is a function with a char parameter called before its declaration with inline parameters.
--- Comment #11 from andreagrassi at sogeasoft dot com 2007-08-29 17:39 --- Subject: R: Error in compiling when there is a function with a char parameter called before its declaration with inline parameters. I accept the answer to gave me but then also the definition of a(a) char a; { ... should be invalid. I don't understand why if I define a(char a) { ... the compiler take a as "char" and don't match with promoted type giving me an error whereas the other way the compiler promotes the "char a" to "int" ALSO IN THE DEFINITION of the function !! Why in summary a(a) char a;// => promoted to int { ... whereas a(char a)// =>remains char { ... The two manner defines the SAME THING (even if in 2 different forms) and MUST be treated identically (like for example "(*a).b" and "a->b" ). You can tell me that your gcc works so, that your gcc treat differently the 2 cases, I accept and I correct my code in order to success, but officially it isn't correct. Then, finishing, I don't understand because you must promote a parameter EXPLICITLY rapresented by a char-constant as 'A' or by a variable previously declared as char, or why, once promoted, you cannot re-correct the signature !! The definition should override the implicitly signature . I know it's from always so, but this is a twist of the logic of the language. However thanks to "raeburn at raeburn dot org" for his kindness, whereas I cannot say so about you and Andrew Pinski, to whom I say to be kinder and to try to develop a product and answer people using more his brain. Le informazioni contenute in questo messaggio di posta elettronica sono di natura confidenziale; qualsiasi pubblicazione, utilizzo o diffusione anche parziale dello stesso non può essere effettuata senza autorizzazione e potrebbe costituire un illecito penale ai sensi del Decreto Legs.vo N° 196/2003 sulla Protezione dei Dati Personali e del Codice Penale, Art. 617-621-635 bis oltre che della legge 547/93. Qualora non siate tra i legittimi destinatari di questa e-mail Vi preghiamo cortesemente di cancellarla dal Vostro sistema dopo aver notificato al mittente, rispondendo alla comunicazione, l'errore da questi commesso. > -Messaggio originale- > Da: manu at gcc dot gnu dot org [mailto:[EMAIL PROTECTED] > Inviato: mercoledì 29 agosto 2007 18.31 > A: [EMAIL PROTECTED] > Oggetto: [Bug c/33219] Error in compiling when there is a > function with > a char parameter called before its declaration with inline parameters. > > > > > --- Comment #9 from manu at gcc dot gnu dot org > 2007-08-29 16:30 --- > Since "a" is called before being defined/declared is assumed: > > extern int a(); > > See also: http://c-faq.com/decl/implfdecl.html > > The error message could be a bit clearer by pointing out this > explicitly: > > a.c:7: error: conflicting types for 'a' > a.c:7: note: an argument type that has a default promotion > can't match an empty > parameter name list declaration > a.c:3: error: previous implicit declaration 'extern int a()' > of 'a' was here > > But I doubt anyone would be interested to work on a patch for > that. Would you? > > > -- > > manu at gcc dot gnu dot org changed: > >What|Removed |Added > -- > -- > CC||manu at gcc > dot gnu dot org > > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33219 > > --- You are receiving this mail because: --- > You reported the bug, or are watching the reporter. > > > > -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33219
[Bug c/33219] Error in compiling when there is a function with a char parameter called before its declaration with inline parameters.
--- Comment #13 from andreagrassi at sogeasoft dot com 2007-08-30 07:54 --- Subject: R: Error in compiling when there is a function with a char parameter called before its declaration with inline parameters. Ok, Ken, I understood. Thank you again for your detailed explanation. Your good manner of answering has been useful for me, unlike the 2 your colleagues... A last thing if you can explain me: Why the compiler report an error in my code, whereas if a modify my invalid code splitting the "main()" and the "a()" functions into different sources and the I compile even no warnings !! Why the compiler is so strict (1 error ) and the linker so permissive (0 warnings) ? If the signature was different even the linker should report an error . If the linker (that is the merger of the functions) is able to use this code merging the 2 functions with different signatures, I don't understand why the compiler should reject my code. Friendly, according to me, this remains not a real error, the compiler could be able to handle this case, don't you ? However, good work to you and all the gcc staff. Bye. Andrea Le informazioni contenute in questo messaggio di posta elettronica sono di natura confidenziale; qualsiasi pubblicazione, utilizzo o diffusione anche parziale dello stesso non può essere effettuata senza autorizzazione e potrebbe costituire un illecito penale ai sensi del Decreto Legs.vo N° 196/2003 sulla Protezione dei Dati Personali e del Codice Penale, Art. 617-621-635 bis oltre che della legge 547/93. Qualora non siate tra i legittimi destinatari di questa e-mail Vi preghiamo cortesemente di cancellarla dal Vostro sistema dopo aver notificato al mittente, rispondendo alla comunicazione, l'errore da questi commesso. > -Messaggio originale- > Da: raeburn at raeburn dot org [mailto:[EMAIL PROTECTED] > Inviato: mercoledì 29 agosto 2007 23.51 > A: [EMAIL PROTECTED] > Oggetto: [Bug c/33219] Error in compiling when there is a > function with > a char parameter called before its declaration with inline parameters. > > > > > --- Comment #12 from raeburn at raeburn dot org > 2007-08-29 21:51 --- > Subject: Re: Error in compiling when there is a function > with a char parameter > called before its declaration with inline parameters. > > On Aug 29, 2007, at 13:39, andreagrassi at sogeasoft dot com wrote: > > I accept the answer to gave me but then also the definition of > > > > a(a) > >char a; > > { > > ... > > > > should be invalid. I don't understand why if I define > > > > a(char a) > > { > > ... > > > > the compiler take a as "char" and don't match with promoted type > > giving me > > an error whereas the other way the compiler promotes the "char a" > > to "int" > > ALSO IN THE DEFINITION of the function !! > > It would seem to make sense, wouldn't it? But that's not how the C > standard was defined. It does cause confusion, but I guess the > benefit of letting "new-style" code be optimized better (e.g., you > can read a byte from memory and stuff it in the argument list, > without having to do the signed or unsigned widening to full "int", > or pass a "float" using 4 bytes on the stack instead of widening it > to an 8-byte "double") while leaving the meaning of "old-style" code > unchanged (old 1970s and 1980s compilers would always do the > "default > promotions", even if it slowed down the code a little) was deemed to > be worth it. I wasn't there, and can't read the minds of the people > on the committee, but it's a fait accompli at this point. > > Note too that in the 1999 version of the standard, the ability to > write the "old-style" code is described an "obsolescent > feature", and > the general direction the standards are moving in seems to suggest > that you should (1) always include a prototype declaration before > calling a function (or include the relevant header for standard C > functions), and (2) always use the prototype-style function > definitions instead of the older style. Having a prototype > declaration in scope before using a function is good practice, > anyways, because it lets the compiler do better type-checking > of your > function call, even if the function definition isn't in the same file. > > > Why in summary > > > > a(a) > >char a;// => promoted to int > > { > > ... > > > > whereas > > > > a(char a)// =>remains char > > { > > ... > > > > The two manner defines
[Bug c/33219] Error in compiling when there is a function with a char parameter called before its declaration with inline parameters.
--- Comment #15 from andreagrassi at sogeasoft dot com 2007-08-31 08:57 --- Subject: R: Error in compiling when there is a function with a char parameter called before its declaration with inline parameters. Thank you again Bye and good work. Le informazioni contenute in questo messaggio di posta elettronica sono di natura confidenziale; qualsiasi pubblicazione, utilizzo o diffusione anche parziale dello stesso non può essere effettuata senza autorizzazione e potrebbe costituire un illecito penale ai sensi del Decreto Legs.vo N° 196/2003 sulla Protezione dei Dati Personali e del Codice Penale, Art. 617-621-635 bis oltre che della legge 547/93. Qualora non siate tra i legittimi destinatari di questa e-mail Vi preghiamo cortesemente di cancellarla dal Vostro sistema dopo aver notificato al mittente, rispondendo alla comunicazione, l'errore da questi commesso. > -Messaggio originale- > Da: raeburn at raeburn dot org [mailto:[EMAIL PROTECTED] > Inviato: venerdì 31 agosto 2007 6.42 > A: [EMAIL PROTECTED] > Oggetto: [Bug c/33219] Error in compiling when there is a > function with > a char parameter called before its declaration with inline parameters. > > > > > --- Comment #14 from raeburn at raeburn dot org > 2007-08-31 04:42 --- > Subject: Re: Error in compiling when there is a function > with a char parameter > called before its declaration with inline parameters. > > On Aug 30, 2007, at 3:55, andreagrassi at sogeasoft dot com wrote: > > A last thing if you can explain me: > > > > Why the compiler report an error in my code, whereas if a > modify my > > invalid > > code splitting the "main()" and the "a()" functions into different > > sources > > and the I compile even no warnings !! Why the compiler is > so strict (1 > > error ) and the linker so permissive (0 warnings) ? > > If the signature was different even the linker should report an > > error . > > In C, there just isn't enough information preserved in the object > files for the linker to do such a check. For the most part, the > object file just has symbol names, executable machine code, > and data, > without a description of what the data structures are, or what types > of arguments are required by the functions. > > If you compile with debugging flags, some of the information > is still > there in the file where the function is defined, so the debugger can > show you the function's arguments. But the file where the call is > made doesn't generally record information about what sort of > arguments it expects the function to take, to the best of my > recollection. So even if the linker parsed the debugging info, it > still wouldn't be able to detect this inconsistency. > > > In terms of the language specification, the program is > incorrect, but > the compiler is not required to detect the problem in this > case, even > if it can't give you a program that works. Yes, in some cases this > really gives a lot of latitude to the compiler writer, and makes it > hard on the application writer. Whether or not the compiler detects > problems that it's not required to is called a "quality of > implementation" issue. > > While gcc can't detect this particular problem you describe above at > compile time or link time, it does have some warning options > that can > help you. For example, you can have it warn you if you call a > function that you haven't declared first. Combine that with a > practice of declaring any function only once in a program, in a > header file included everywhere you use the function and where you > define it, and it ensures that you have consistent declarations for > your functions. > > > It might be theoretically possible to have the compiler write some > additional information into the object files, and change the linker > look for that information. But as the object file format and the > linker implementation are very system-specific, parts of it would > have to be implemented over and over for different kinds of > systems. > And while the GNU project does have a linker available in the > binutils package, it doesn't support all systems, so even once it's > done, it would still only get you the warnings you want on some > systems and not on others. I won't say no one's going to > tackle such > a project, but personally I doubt it's going to be a high priority > for many people, especially given that coding practices like I > described above can take care of most cases of this kind of problem. > > Ken > > > -- > > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33219 > > --- You are receiving this mail because: --- > You reported the bug, or are watching the reporter. > > > > -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33219