You are not logged in.

#1 2020-01-30 09:02:09

johannkokos
Member
Registered: 2018-02-27
Posts: 12

Add -std=c11 option cause gcc to complain implicit declaration of func

#include <stdio.h>
#include <unistd.h>

int main()
{
    printf("%p\n", sbrk(0));
}

Code above is compiled without any warning with this,

gcc -Wall -Wextra -Wpedantic brk.c

However, adding -std=c11 to it, the compiler starts to complain,

brk.c: In function ‘main’:
brk.c:6:20: warning: implicit declaration of function ‘sbrk’ [-Wimplicit-function-declaration]
    6 |     printf("%p\n", sbrk(0));
      |                    ^~~~
brk.c:6:14: warning: format ‘%p’ expects argument of type ‘void *’, but argument 2 has type ‘int’ [-Wformat=]
    6 |     printf("%p\n", sbrk(0));
      |             ~^     ~~~~~~~
      |              |     |
      |              |     int
      |              void *
      |             %d

I understand without -std option, gcc defaults to gnu11. But I don't see how does affect the function declaration lookup.

Is this intended?

Offline

#2 2020-01-31 00:27:36

ayekat
Member
Registered: 2011-01-17
Posts: 1,385
Website

Re: Add -std=c11 option cause gcc to complain implicit declaration of func

johannkokos wrote:

But I don't see how does affect the function declaration lookup.

gnu11 supports more things in the standard C library than POSIX/ISO. It is to be expected that things that work with gnu11 won't necessarily also work with c11.

On a technical level, the standard you choose has an effect on which macros will be defined in /usr/include/features.h. You will see that these macros are then also used to guard the definition of `sbrk` in /usr/include/unistd.h.


{,META,RE}PKGBUILDSpacman-hacks (includes makemetapkg and remakepkg) │ dotfiles

Offline

Board footer

Powered by FluxBB