Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   compile error (http://www.velocityreviews.com/forums/t743773-compile-error.html)

Ceriousmall 02-18-2011 03:45 AM

compile error
 
Why is this program not compiling when the Gcc command is used . This
is a out of the K&R book, Gcc 4.4.4 Slackware 13.1 x86_64 . the error
is........conflicting types for 'getline'
note
previous declaration of 'getline' was here
It does however compile with the g++ command..........This is the
code..........................
..
..
/* program prints longest input line */
#include <stdio.h>

#define MAXLINE 1000 /* maximum input line size */

int getline(char line[], int maxline);
void copy(char to[], char from[]);

int main(void)
{
int len; /* current line length */
int max; /* maximum length seen so far */
char line[MAXLINE]; /* current input line */
char longest[MAXLINE]; /* longest line saved here */

max = 0;

while ((len = getline(line, MAXLINE)) > 0)
if (len > max) {
max = len;
copy(longest, line);
}
if (max > 0) /* there was a line */
printf("%s", longest);

return 0;
}

/* getline: read a line into s, return length */
int getline(char s[], int lim)
{
int c, i;

for (i = 0; i < lim-1 && (c = getchar()) != EOF && c != '\n'; ++i)
s[i] = c;
if (c == '\n') {
s[i] = c;
++i;
}
s[i] = '\0';

return i;
}

/* copy: copy 'from' into 'to'; assume to is big enough */
void copy(char to[], char from[])
{
int i;

i = 0;

while ((to[i] = from [i]) != '\0')
++i;
}




Ian Collins 02-18-2011 03:51 AM

Re: compile error
 
On 02/18/11 04:45 PM, Ceriousmall wrote:
> Why is this program not compiling when the Gcc command is used . This
> is a out of the K&R book, Gcc 4.4.4 Slackware 13.1 x86_64 . the error
> is........conflicting types for 'getline'


Your system headers probably do a naughty and declare their own getline
in <stdio.h>.

Try invoking gcc in a conforming mode (gcc -ansi -pedantic -Wall).

--
Ian Collins

Seebs 02-18-2011 07:25 PM

Re: compile error
 
On 2011-02-18, Ceriousmall <divadsmall@gmail.com> wrote:
> Why is this program not compiling when the Gcc command is used . This
> is a out of the K&R book, Gcc 4.4.4 Slackware 13.1 x86_64 . the error
> is........conflicting types for 'getline'


The reason is that the glibc developers are utterly and totally opposed
to any kind of basic sanity in their development process.

Basically, glibc declares a function with the name "getline" and makes it
part of the system implementation. It does this despite the fact that
the name in question was widely used (including, as you note, being used
in examples in K&R) and was in a namespace reserved for users.

This is, I believe, the single dumbest implementation decision I have ever
seen in any C compiler or C library. And that is, I will point out, a
field with very stiff competition.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.

Seebs 02-18-2011 07:26 PM

Re: compile error
 
On 2011-02-18, Jonathan Leffler <jleffler@earthlink.net> wrote:
> getline() is a recent addition to the POSIX 2008 standard that is being
> exposed to you. Everybody who has their own implementation of getline()
> and does not ensure that POSIX functions are not made visible (or who
> needs other POSIX functions from <stdio.h>) will get burned by it until
> they rename their function.


....

I take back what I said about glibc.

This is the single stupidest standardization decision I have ever seen. It
would never have occurred to me that the POSIX people could do something
*this* stupid. ... And yes, I know how extreme a statement that is. :)

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.

Ian Collins 02-18-2011 09:02 PM

Re: compile error
 
On 02/19/11 08:26 AM, Seebs wrote:
> On 2011-02-18, Jonathan Leffler<jleffler@earthlink.net> wrote:
>> getline() is a recent addition to the POSIX 2008 standard that is being
>> exposed to you. Everybody who has their own implementation of getline()
>> and does not ensure that POSIX functions are not made visible (or who
>> needs other POSIX functions from<stdio.h>) will get burned by it until
>> they rename their function.

>
> ....
>
> I take back what I said about glibc.
>
> This is the single stupidest standardization decision I have ever seen. It
> would never have occurred to me that the POSIX people could do something
> *this* stupid. ... And yes, I know how extreme a statement that is. :)


This isn't the only POSIX function to be found in <stdio.h>. The
problem is gcc includes POSIX extensions in its default mode.

--
Ian Collins

Keith Thompson 02-18-2011 09:42 PM

Re: compile error
 
Ian Collins <ian-news@hotmail.com> writes:
> On 02/19/11 08:26 AM, Seebs wrote:
>> On 2011-02-18, Jonathan Leffler<jleffler@earthlink.net> wrote:
>>> getline() is a recent addition to the POSIX 2008 standard that is being
>>> exposed to you. Everybody who has their own implementation of getline()
>>> and does not ensure that POSIX functions are not made visible (or who
>>> needs other POSIX functions from<stdio.h>) will get burned by it until
>>> they rename their function.

>>
>> ....
>>
>> I take back what I said about glibc.
>>
>> This is the single stupidest standardization decision I have ever seen. It
>> would never have occurred to me that the POSIX people could do something
>> *this* stupid. ... And yes, I know how extreme a statement that is. :)

>
> This isn't the only POSIX function to be found in <stdio.h>. The
> problem is gcc includes POSIX extensions in its default mode.


How much of a problem is that, though? I suspect that most gcc users
would rather have POSIX available by default than not.

(I really wish POSIX had been able to avoid adding non-standard
functions to the C standard headers, but some of those headers,
including what are now POSIX-specific declarations, predate the
C standard.)

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Ian Collins 02-18-2011 09:54 PM

Re: compile error
 
On 02/19/11 10:42 AM, Keith Thompson wrote:
> Ian Collins<ian-news@hotmail.com> writes:
>> On 02/19/11 08:26 AM, Seebs wrote:
>>> On 2011-02-18, Jonathan Leffler<jleffler@earthlink.net> wrote:
>>>> getline() is a recent addition to the POSIX 2008 standard that is being
>>>> exposed to you. Everybody who has their own implementation of getline()
>>>> and does not ensure that POSIX functions are not made visible (or who
>>>> needs other POSIX functions from<stdio.h>) will get burned by it until
>>>> they rename their function.
>>>
>>> ....
>>>
>>> I take back what I said about glibc.
>>>
>>> This is the single stupidest standardization decision I have ever seen. It
>>> would never have occurred to me that the POSIX people could do something
>>> *this* stupid. ... And yes, I know how extreme a statement that is. :)

>>
>> This isn't the only POSIX function to be found in<stdio.h>. The
>> problem is gcc includes POSIX extensions in its default mode.

>
> How much of a problem is that, though? I suspect that most gcc users
> would rather have POSIX available by default than not.


In the context of this post it is the problem!

--
Ian Collins

Seebs 02-18-2011 10:30 PM

Re: compile error
 
On 2011-02-18, Ian Collins <ian-news@hotmail.com> wrote:
> On 02/19/11 08:26 AM, Seebs wrote:
>> This is the single stupidest standardization decision I have ever seen. It
>> would never have occurred to me that the POSIX people could do something
>> *this* stupid. ... And yes, I know how extreme a statement that is. :)


> This isn't the only POSIX function to be found in <stdio.h>. The
> problem is gcc includes POSIX extensions in its default mode.


No, the problem is POSIX inventing a new function and giving it a name
that was not only in the user's namespace, *but very widely used*. In
programs that had been running on UNIX machines for years.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.

Ian Collins 02-18-2011 10:50 PM

Re: compile error
 
On 02/19/11 11:30 AM, Seebs wrote:
> On 2011-02-18, Ian Collins<ian-news@hotmail.com> wrote:
>> On 02/19/11 08:26 AM, Seebs wrote:
>>> This is the single stupidest standardization decision I have ever seen. It
>>> would never have occurred to me that the POSIX people could do something
>>> *this* stupid. ... And yes, I know how extreme a statement that is. :)

>
>> This isn't the only POSIX function to be found in<stdio.h>. The
>> problem is gcc includes POSIX extensions in its default mode.

>
> No, the problem is POSIX inventing a new function and giving it a name
> that was not only in the user's namespace, *but very widely used*. In
> programs that had been running on UNIX machines for years.


Did they define a new function, or standardise existing (glibc)
practice? I've never used getline, but I'm sure it has been 'standard"
on Linux for a long time.

--
Ian Collins

Seebs 02-18-2011 11:38 PM

Re: compile error
 
On 2011-02-18, Ian Collins <ian-news@hotmail.com> wrote:
> Did they define a new function, or standardise existing (glibc)
> practice? I've never used getline, but I'm sure it has been 'standard"
> on Linux for a long time.


Sort of. If you look at the dozens of compilation problems introduced by
this, the thing is that a lot of GNU tools *provide their own*... using a
standard interface.

Which is different from this one.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.


All times are GMT. The time now is 12:10 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57