public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/30426]  New: Warning when using strndup
@ 2007-01-10 20:33 raimund at cs dot auckland dot ac dot nz
  2007-01-10 20:38 ` [Bug c/30426] " pinskia at gcc dot gnu dot org
  2007-01-10 20:38 ` schwab at suse dot de
  0 siblings, 2 replies; 3+ messages in thread
From: raimund at cs dot auckland dot ac dot nz @ 2007-01-10 20:33 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1360 bytes --]

The tiny test program below produces a warning (specifics commented in code
below). From my understanding, no warning should appear on compilation.
Current workaround: Warning disappears once line 2 (right after #include) is
uncommented.

Code:
---------------------------------------------------------------
#include <string.h>
// extern char *strndup (__const char *__string, size_t __n);

int main() {
  char *str="one two three",
       *one=0;

  // command below produces warning
  // "a.c:18: warning: assignment makes pointer from integer without a cast"
  // on openSuSE 10.0 (gcc (GCC) 4.0.2 20050901 (prerelease) (SUSE Linux))

  // command below produces warning
  // "a.c:18: warning: incompatible implicit declaration of built-in function
‘strndup’"
  // on openSuSE 10.2 (gcc (GCC) 4.1.2 20061115 (prerelease) (SUSE Linux))

  // warnings disappear when line 3 is uncommented.

  one = strndup(str,3);
}
---------------------------------------------------------------


-- 
           Summary: Warning when using strndup
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: raimund at cs dot auckland dot ac dot nz


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30426


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/30426] Warning when using strndup
  2007-01-10 20:33 [Bug c/30426] New: Warning when using strndup raimund at cs dot auckland dot ac dot nz
@ 2007-01-10 20:38 ` pinskia at gcc dot gnu dot org
  2007-01-10 20:38 ` schwab at suse dot de
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-01-10 20:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2007-01-10 20:38 -------
Not a bug, strndup is a GNU (glibc) extension.  You have to use -D_GNU_SOURCE
when compiling.
The warning messages are correct as there is no prototype for strndup.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30426


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/30426] Warning when using strndup
  2007-01-10 20:33 [Bug c/30426] New: Warning when using strndup raimund at cs dot auckland dot ac dot nz
  2007-01-10 20:38 ` [Bug c/30426] " pinskia at gcc dot gnu dot org
@ 2007-01-10 20:38 ` schwab at suse dot de
  1 sibling, 0 replies; 3+ messages in thread
From: schwab at suse dot de @ 2007-01-10 20:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from schwab at suse dot de  2007-01-10 20:37 -------
strndup is a GNU extension and is only declared in <string.h> when _GNU_SOURCE
is defined.


-- 

schwab at suse dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30426


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-01-10 20:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-10 20:33 [Bug c/30426] New: Warning when using strndup raimund at cs dot auckland dot ac dot nz
2007-01-10 20:38 ` [Bug c/30426] " pinskia at gcc dot gnu dot org
2007-01-10 20:38 ` schwab at suse dot de

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).