Unix Programming - GCC bug? ( GNU getline() )

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > June 2004 > GCC bug? ( GNU getline() )





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author GCC bug? ( GNU getline() )
tweak

2004-06-17, 5:55 pm

I'm currently using GCC 3.2-7. Yeah, I need to upgrade,
but I need a better box first to handle the bloated
desktop in Fedora (which I only use for web use).

Here's the bug:

I receive a warning that I have implicitly declared
getline(). Now, per the GNU glibc documentation,
I should only have to declare stdio.h.

my compiler options were:

-std=gnu99 -g -Wall -aux-info filename -o a.out a.c

in the file generated by -aux-info, it looks like:

extern int getline (/* ??? */);

now, when I look in stdio.h (/usr/include/stdio.h), getline is
defined as:

extern _IO_ssize_t getline (char ** __restrict __lineptr,
size_t *__restrict __n,
FILE *__restrict __stream) __THROW;

now I could find no definition for __IO_ssize_t in stdio.h, and
I have no idea where to look externally besides unistd.h and
/bits/types.h and /sys/types.h

Am I doing something wrong? I am just trying to better utilize
the GNU extensions and clean up any possible buffer overflows in
my code.

Thanks,

Brian

Måns Rullgård

2004-06-17, 5:55 pm

tweak <xbwaichunasx@cox.net> writes:

> I'm currently using GCC 3.2-7. Yeah, I need to upgrade,
> but I need a better box first to handle the bloated
> desktop in Fedora (which I only use for web use).
>
> Here's the bug:
>
> I receive a warning that I have implicitly declared
> getline(). Now, per the GNU glibc documentation,
> I should only have to declare stdio.h.


#define _GNU_SOURCE before you #include stdio.h.

--
Måns Rullgård
mru@kth.se
Nils O. Selåsdal

2004-06-17, 5:55 pm

On Wed, 16 Jun 2004 22:32:45 -0700, tweak wrote:

> I'm currently using GCC 3.2-7. Yeah, I need to upgrade,
> but I need a better box first to handle the bloated
> desktop in Fedora (which I only use for web use).
>
> Here's the bug:
>
> I receive a warning that I have implicitly declared
> getline(). Now, per the GNU glibc documentation,
> I should only have to declare stdio.h.
>
> my compiler options were:
>
> -std=gnu99 -g -Wall -aux-info filename -o a.out a.c
>
> in the file generated by -aux-info, it looks like:
>
> extern int getline (/* ??? */);
>
> now, when I look in stdio.h (/usr/include/stdio.h), getline is
> defined as:
>
> extern _IO_ssize_t getline (char ** __restrict __lineptr,
> size_t *__restrict __n,
> FILE *__restrict __stream) __THROW;
>
> now I could find no definition for __IO_ssize_t in stdio.h, and
> I have no idea where to look externally besides unistd.h and
> /bits/types.h and /sys/types.h

Well, stdio.h on linux includes atleast stddef.h, features.h,
bits/types.h and libio.h

> Am I doing something wrong? I am just trying to better utilize
> the GNU extensions and clean up any possible buffer overflows in
> my code.

Defining your own prototypes is almost always wrong.
> Thanks,
>
> Brian

If you peek at the stdio.h header, you'll notice you'll notice it's under
an #ifdef __USE_GNU , and them manpage says you'll have to
#define _GNU_SOURCE
#include <stdio.h>



Floyd L. Davidson

2004-06-17, 5:55 pm

Måns Rullgård <mru@kth.se> wrote:
>tweak <xbwaichunasx@cox.net> writes:
>
>
>#define _GNU_SOURCE before you #include stdio.h.


And see /usr/include/features.h for details on that particular
define and several others that specify a specific environment.

--
FloydL. Davidson <http://web.newsguy.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) floyd@barrow.com
Prasad

2004-06-17, 5:55 pm

tweak <xbwaichunasx@cox.net> wrote in message news:<m3aAc.75407$My6.39132@fed1read05>...
> extern _IO_ssize_t getline (char ** __restrict __lineptr,
> size_t *__restrict __n,
> FILE *__restrict __stream) __THROW;
>
> now I could find no definition for __IO_ssize_t in stdio.h, and
> I have no idea where to look externally besides unistd.h and
> /bits/types.h and /sys/types.h



Hello Brian, actually it is _IO_ssize_t and ...

1) _IO_ssize_t : has been defined as follows in /usr/include/libio.h

#define _IO_ssize_t _G_ssize_t

2) _G_ssize_t : has been defined as follows in /usr/include/_G_config.h

#define _G_size_t size_t

3) size_t : has been defined as follows in /usr/include/linux/types.h

typedef __kernel_size_t size_t

4)__kernel_size_t : has been defined as follows in
/usr/include/asm/posix_types.h

typedef unsigned int __kernel_size_t

Hope this'll suffise your need...

Bye
-Prasad

[PS : grep and man command is answer for almost all questions...]
tweak

2004-06-17, 5:55 pm

Floyd L. Davidson wrote:
> Måns Rullgård <mru@kth.se> wrote:
>
>
>
> And see /usr/include/features.h for details on that particular
> define and several others that specify a specific environment.
>


Thanks! I knew I was just doing something stupid.

Brian

tweak

2004-06-17, 11:51 pm

Prasad wrote:
> tweak <xbwaichunasx@cox.net> wrote in message news:<m3aAc.75407$My6.39132@fed1read05>...
>
>
>
>
> Hello Brian, actually it is _IO_ssize_t and ...


Sorry about the typo.

>
> 1) _IO_ssize_t : has been defined as follows in /usr/include/libio.h
>
> #define _IO_ssize_t _G_ssize_t
>
> 2) _G_ssize_t : has been defined as follows in /usr/include/_G_config.h
>
> #define _G_size_t size_t
>
> 3) size_t : has been defined as follows in /usr/include/linux/types.h
>
> typedef __kernel_size_t size_t
>
> 4)__kernel_size_t : has been defined as follows in
> /usr/include/asm/posix_types.h
>
> typedef unsigned int __kernel_size_t
>
> Hope this'll suffise your need...
>
> Bye
> -Prasad
>
> [PS : grep and man command is answer for almost all questions...]


Thanks. I cannot believe these definitions are so many layers down. It
makes reading the code very time consuming. Are there any programming
interfaces, where I can visually see the trees of these definitions? I
am currently writing my code in VIM and compiling at the command line.

--

I had overlooked the section "Feature Test Macros" in the GNU C library
documentation, which I did find today at work. I have been just
concentrating on programming in ISO C99 with some POSIX stuff. This was
the first time I started to dive into the GNU extensions, which I
thought would be cover with the compiler command: -std=gnu99. Of
course, I know this is wrong now.

Thanks,

Brian

P.S. I think I use grep more than I use ls.
Alan D. Salewski

2004-06-26, 10:11 am

On 2004-06-18, tweak <xbwaichunasx@cox.net> wrote:
[...]
> Thanks. I cannot believe these definitions are so many layers down. It
> makes reading the code very time consuming. Are there any programming
> interfaces, where I can visually see the trees of these definitions? I
> am currently writing my code in VIM and compiling at the command line.

[...]

You might want to look into 'cscope'. It won't give you a visual tree of
definitions, but will make it easy to jump to a symbol's definition.

-Al

--
-----------------------------------------------------------------
a l a n d. s a l e w s k i salewski@worldnet.att.net
1024D/FA2C3588 EDFA 195F EDF1 0933 1002 6396 7C92 5CB3 FA2C 3588
-----------------------------------------------------------------
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com