Why does -std=c11 with gcc hide popen in stdio.h? [duplicate]











up vote
0
down vote

favorite













This question already has an answer here:




  • popen implicitly declared even though #include <stdio.h> is added

    3 answers




I want to use popen. It is in stdio.h. I include that, but the compiler doesn't see it with
-std=c11. It does compile without -std=c11.



#include <stdio.h>

int main(void)
{
popen("ls *","r");
}



gcc -std=c11 popen_test.c




popen_test.c: In function ‘main’:

popen_test.c:5:4: warning: implicit declaration of function ‘popen’ [-Wimplicit-function-declaration]




popen("ls *","r");
^~~~~



It is hidden in stdio.h with



#ifdef __USE_POSIX2


The man page says it is available if:




_POSIX_C_SOURCE >= 2 || /* Glibc versions <= 2.19: */
_BSD_SOURCE || _SVID_SOURCE











share|improve this question















marked as duplicate by tmlen, melpomene c
Users with the  c badge can single-handedly close c questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 10 at 20:19


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • popen is not part of standard C.
    – melpomene
    Nov 10 at 20:14










  • @melpomene Can you turn -std=c11 on and off in the source code?
    – Scooter
    Nov 10 at 20:15












  • What do you mean by that? Or maybe a better question: What are you trying to achieve by specifying -std=c11?
    – melpomene
    Nov 10 at 20:16










  • @melpomene I want all the features of C11
    – Scooter
    Nov 10 at 20:17






  • 3




    Well, e.g. -std=gnu11 would give you that plus all GNU extensions.
    – melpomene
    Nov 10 at 20:17















up vote
0
down vote

favorite













This question already has an answer here:




  • popen implicitly declared even though #include <stdio.h> is added

    3 answers




I want to use popen. It is in stdio.h. I include that, but the compiler doesn't see it with
-std=c11. It does compile without -std=c11.



#include <stdio.h>

int main(void)
{
popen("ls *","r");
}



gcc -std=c11 popen_test.c




popen_test.c: In function ‘main’:

popen_test.c:5:4: warning: implicit declaration of function ‘popen’ [-Wimplicit-function-declaration]




popen("ls *","r");
^~~~~



It is hidden in stdio.h with



#ifdef __USE_POSIX2


The man page says it is available if:




_POSIX_C_SOURCE >= 2 || /* Glibc versions <= 2.19: */
_BSD_SOURCE || _SVID_SOURCE











share|improve this question















marked as duplicate by tmlen, melpomene c
Users with the  c badge can single-handedly close c questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 10 at 20:19


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • popen is not part of standard C.
    – melpomene
    Nov 10 at 20:14










  • @melpomene Can you turn -std=c11 on and off in the source code?
    – Scooter
    Nov 10 at 20:15












  • What do you mean by that? Or maybe a better question: What are you trying to achieve by specifying -std=c11?
    – melpomene
    Nov 10 at 20:16










  • @melpomene I want all the features of C11
    – Scooter
    Nov 10 at 20:17






  • 3




    Well, e.g. -std=gnu11 would give you that plus all GNU extensions.
    – melpomene
    Nov 10 at 20:17













up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:




  • popen implicitly declared even though #include <stdio.h> is added

    3 answers




I want to use popen. It is in stdio.h. I include that, but the compiler doesn't see it with
-std=c11. It does compile without -std=c11.



#include <stdio.h>

int main(void)
{
popen("ls *","r");
}



gcc -std=c11 popen_test.c




popen_test.c: In function ‘main’:

popen_test.c:5:4: warning: implicit declaration of function ‘popen’ [-Wimplicit-function-declaration]




popen("ls *","r");
^~~~~



It is hidden in stdio.h with



#ifdef __USE_POSIX2


The man page says it is available if:




_POSIX_C_SOURCE >= 2 || /* Glibc versions <= 2.19: */
_BSD_SOURCE || _SVID_SOURCE











share|improve this question
















This question already has an answer here:




  • popen implicitly declared even though #include <stdio.h> is added

    3 answers




I want to use popen. It is in stdio.h. I include that, but the compiler doesn't see it with
-std=c11. It does compile without -std=c11.



#include <stdio.h>

int main(void)
{
popen("ls *","r");
}



gcc -std=c11 popen_test.c




popen_test.c: In function ‘main’:

popen_test.c:5:4: warning: implicit declaration of function ‘popen’ [-Wimplicit-function-declaration]




popen("ls *","r");
^~~~~



It is hidden in stdio.h with



#ifdef __USE_POSIX2


The man page says it is available if:




_POSIX_C_SOURCE >= 2 || /* Glibc versions <= 2.19: */
_BSD_SOURCE || _SVID_SOURCE






This question already has an answer here:




  • popen implicitly declared even though #include <stdio.h> is added

    3 answers








c popen






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 20:15

























asked Nov 10 at 20:11









Scooter

3,51662749




3,51662749




marked as duplicate by tmlen, melpomene c
Users with the  c badge can single-handedly close c questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 10 at 20:19


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by tmlen, melpomene c
Users with the  c badge can single-handedly close c questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 10 at 20:19


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • popen is not part of standard C.
    – melpomene
    Nov 10 at 20:14










  • @melpomene Can you turn -std=c11 on and off in the source code?
    – Scooter
    Nov 10 at 20:15












  • What do you mean by that? Or maybe a better question: What are you trying to achieve by specifying -std=c11?
    – melpomene
    Nov 10 at 20:16










  • @melpomene I want all the features of C11
    – Scooter
    Nov 10 at 20:17






  • 3




    Well, e.g. -std=gnu11 would give you that plus all GNU extensions.
    – melpomene
    Nov 10 at 20:17


















  • popen is not part of standard C.
    – melpomene
    Nov 10 at 20:14










  • @melpomene Can you turn -std=c11 on and off in the source code?
    – Scooter
    Nov 10 at 20:15












  • What do you mean by that? Or maybe a better question: What are you trying to achieve by specifying -std=c11?
    – melpomene
    Nov 10 at 20:16










  • @melpomene I want all the features of C11
    – Scooter
    Nov 10 at 20:17






  • 3




    Well, e.g. -std=gnu11 would give you that plus all GNU extensions.
    – melpomene
    Nov 10 at 20:17
















popen is not part of standard C.
– melpomene
Nov 10 at 20:14




popen is not part of standard C.
– melpomene
Nov 10 at 20:14












@melpomene Can you turn -std=c11 on and off in the source code?
– Scooter
Nov 10 at 20:15






@melpomene Can you turn -std=c11 on and off in the source code?
– Scooter
Nov 10 at 20:15














What do you mean by that? Or maybe a better question: What are you trying to achieve by specifying -std=c11?
– melpomene
Nov 10 at 20:16




What do you mean by that? Or maybe a better question: What are you trying to achieve by specifying -std=c11?
– melpomene
Nov 10 at 20:16












@melpomene I want all the features of C11
– Scooter
Nov 10 at 20:17




@melpomene I want all the features of C11
– Scooter
Nov 10 at 20:17




3




3




Well, e.g. -std=gnu11 would give you that plus all GNU extensions.
– melpomene
Nov 10 at 20:17




Well, e.g. -std=gnu11 would give you that plus all GNU extensions.
– melpomene
Nov 10 at 20:17












1 Answer
1






active

oldest

votes

















up vote
1
down vote













popen is not part of C. To get it, you need to enable it with a feature test macro before including anything.



The simplest way to do it is with a #define _GNU_SOURCE at the top (or with -D_GNU_SOURCE in your compiler invocation).



compiles with -std=c11:



#define _GNU_SOURCE
#include <stdio.h>

int main(void)
{
popen("ls *","r");
}





share|improve this answer





















  • Does -std=c11 mean "don't allow anything that isn't part of C11"? I was hoping for "allow anything that is part of C11".
    – Scooter
    Nov 10 at 20:20








  • 1




    @Scooter I'd say it's more like that calling gcc without a specific standards gives you some extra gnu stuff (-std=gnu11 or whatever your compiler defaults to). -std=c11 disables it so that the identifiers that the C standard says should belong to you aren't taken.
    – PSkocik
    Nov 10 at 20:23






  • 2




    @Scooter int popen; int main(void) { return popen; } is a valid C11 program, but it would conflict with the popen function.
    – melpomene
    Nov 10 at 20:24


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













popen is not part of C. To get it, you need to enable it with a feature test macro before including anything.



The simplest way to do it is with a #define _GNU_SOURCE at the top (or with -D_GNU_SOURCE in your compiler invocation).



compiles with -std=c11:



#define _GNU_SOURCE
#include <stdio.h>

int main(void)
{
popen("ls *","r");
}





share|improve this answer





















  • Does -std=c11 mean "don't allow anything that isn't part of C11"? I was hoping for "allow anything that is part of C11".
    – Scooter
    Nov 10 at 20:20








  • 1




    @Scooter I'd say it's more like that calling gcc without a specific standards gives you some extra gnu stuff (-std=gnu11 or whatever your compiler defaults to). -std=c11 disables it so that the identifiers that the C standard says should belong to you aren't taken.
    – PSkocik
    Nov 10 at 20:23






  • 2




    @Scooter int popen; int main(void) { return popen; } is a valid C11 program, but it would conflict with the popen function.
    – melpomene
    Nov 10 at 20:24















up vote
1
down vote













popen is not part of C. To get it, you need to enable it with a feature test macro before including anything.



The simplest way to do it is with a #define _GNU_SOURCE at the top (or with -D_GNU_SOURCE in your compiler invocation).



compiles with -std=c11:



#define _GNU_SOURCE
#include <stdio.h>

int main(void)
{
popen("ls *","r");
}





share|improve this answer





















  • Does -std=c11 mean "don't allow anything that isn't part of C11"? I was hoping for "allow anything that is part of C11".
    – Scooter
    Nov 10 at 20:20








  • 1




    @Scooter I'd say it's more like that calling gcc without a specific standards gives you some extra gnu stuff (-std=gnu11 or whatever your compiler defaults to). -std=c11 disables it so that the identifiers that the C standard says should belong to you aren't taken.
    – PSkocik
    Nov 10 at 20:23






  • 2




    @Scooter int popen; int main(void) { return popen; } is a valid C11 program, but it would conflict with the popen function.
    – melpomene
    Nov 10 at 20:24













up vote
1
down vote










up vote
1
down vote









popen is not part of C. To get it, you need to enable it with a feature test macro before including anything.



The simplest way to do it is with a #define _GNU_SOURCE at the top (or with -D_GNU_SOURCE in your compiler invocation).



compiles with -std=c11:



#define _GNU_SOURCE
#include <stdio.h>

int main(void)
{
popen("ls *","r");
}





share|improve this answer












popen is not part of C. To get it, you need to enable it with a feature test macro before including anything.



The simplest way to do it is with a #define _GNU_SOURCE at the top (or with -D_GNU_SOURCE in your compiler invocation).



compiles with -std=c11:



#define _GNU_SOURCE
#include <stdio.h>

int main(void)
{
popen("ls *","r");
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 10 at 20:19









PSkocik

31.2k54568




31.2k54568












  • Does -std=c11 mean "don't allow anything that isn't part of C11"? I was hoping for "allow anything that is part of C11".
    – Scooter
    Nov 10 at 20:20








  • 1




    @Scooter I'd say it's more like that calling gcc without a specific standards gives you some extra gnu stuff (-std=gnu11 or whatever your compiler defaults to). -std=c11 disables it so that the identifiers that the C standard says should belong to you aren't taken.
    – PSkocik
    Nov 10 at 20:23






  • 2




    @Scooter int popen; int main(void) { return popen; } is a valid C11 program, but it would conflict with the popen function.
    – melpomene
    Nov 10 at 20:24


















  • Does -std=c11 mean "don't allow anything that isn't part of C11"? I was hoping for "allow anything that is part of C11".
    – Scooter
    Nov 10 at 20:20








  • 1




    @Scooter I'd say it's more like that calling gcc without a specific standards gives you some extra gnu stuff (-std=gnu11 or whatever your compiler defaults to). -std=c11 disables it so that the identifiers that the C standard says should belong to you aren't taken.
    – PSkocik
    Nov 10 at 20:23






  • 2




    @Scooter int popen; int main(void) { return popen; } is a valid C11 program, but it would conflict with the popen function.
    – melpomene
    Nov 10 at 20:24
















Does -std=c11 mean "don't allow anything that isn't part of C11"? I was hoping for "allow anything that is part of C11".
– Scooter
Nov 10 at 20:20






Does -std=c11 mean "don't allow anything that isn't part of C11"? I was hoping for "allow anything that is part of C11".
– Scooter
Nov 10 at 20:20






1




1




@Scooter I'd say it's more like that calling gcc without a specific standards gives you some extra gnu stuff (-std=gnu11 or whatever your compiler defaults to). -std=c11 disables it so that the identifiers that the C standard says should belong to you aren't taken.
– PSkocik
Nov 10 at 20:23




@Scooter I'd say it's more like that calling gcc without a specific standards gives you some extra gnu stuff (-std=gnu11 or whatever your compiler defaults to). -std=c11 disables it so that the identifiers that the C standard says should belong to you aren't taken.
– PSkocik
Nov 10 at 20:23




2




2




@Scooter int popen; int main(void) { return popen; } is a valid C11 program, but it would conflict with the popen function.
– melpomene
Nov 10 at 20:24




@Scooter int popen; int main(void) { return popen; } is a valid C11 program, but it would conflict with the popen function.
– melpomene
Nov 10 at 20:24



Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues