Opened 9 months ago

Closed 8 months ago

#27900 closed defect (not a bug)

Please establish which C standard tor code complies with

Reported by: yurivict271 Owned by:
Priority: Medium Milestone: Tor: 0.3.5.x-final
Component: Core Tor/Tor Version:
Severity: Normal Keywords:
Cc: Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description

Currently, tor is built without the -std=xx flag, and it isn't clear what C standard is compiler expected to use.

Please add one of -std=c90, -std=c99, -std=c11, -std=c17 to compilation lines, add the corresponding macro to configure.ac:

AX_CHECK_COMPILE_FLAG([-std=cNN], [CFLAGS="$CFLAGS -std=cNN"])

Reason#1: in FreeBSD we have several architectures some of which use different compilers (gcc/clang/etc) It is good to take guessing from the process and establish what standard the code complies with.

Reason#2: Some compilers might default to the older standard where a newer standard is required.

My guess is that the standard is c11.

Child Tickets

Change History (8)

comment:1 Changed 9 months ago by nickm

Component: - Select a componentCore Tor/Tor
Milestone: Tor: 0.3.5.x-final

comment:2 Changed 9 months ago by nickm

We require several C99 features; I don't think we require any C11. Adding a flag would be fine.

comment:3 Changed 9 months ago by nickm

Hang on though -- we do AC_PROG_CC_C99 in our configure.ac file. Is that not enough?

comment:4 Changed 9 months ago by yurivict271

AC_PROG_CC_C99 is maybe enough to check the compiler, but it doesn't add -std=c99.

comment:5 Changed 9 months ago by yurivict271

Morover, when I add -std=c99, compilation with clang breaks:

src/common/di_ops.c:158:5: warning: implicit declaration of function 'typeof' is invalid in C99 [-Wimplicit-function-declaration]
    tor_free(victim);
    ^
./src/common/util.h:90:5: note: expanded from macro 'tor_free'
    typeof(&(p)) tor_free__tmpvar = &(p);                      \
    ^
src/common/di_ops.c:158:5: warning: this function declaration is not a prototype [-Wstrict-prototypes]
./src/common/util.h:90:5: note: expanded from macro 'tor_free'
    typeof(&(p)) tor_free__tmpvar = &(p);                      \
    ^
src/common/di_ops.c:158:5: error: expected ';' after expression
./src/common/util.h:90:18: note: expanded from macro 'tor_free'
    typeof(&(p)) tor_free__tmpvar = &(p);                      \
                 ^
src/common/di_ops.c:158:5: error: use of undeclared identifier 'tor_free__tmpvar'
./src/common/util.h:90:18: note: expanded from macro 'tor_free'
    typeof(&(p)) tor_free__tmpvar = &(p);                      \
                 ^

So it is something else, not c99.

Last edited 9 months ago by yurivict271 (previous) (diff)

comment:6 in reply to:  5 Changed 9 months ago by cyberpunks

Replying to yurivict271:

So it is something else, not c99.

Did you try -std=gnu99? typeof is a nonstandard GCC extension. It's not in C11 either.

Last edited 9 months ago by cyberpunks (previous) (diff)

comment:7 Changed 9 months ago by yurivict271

Yes, it builds with -std=gnu99.

comment:8 Changed 8 months ago by dgoulet

Resolution: not a bug
Status: newclosed

I really don't see any other action items here. -std=gnu99 is what is being used and we do have the AC_PROG_CC_C99 being used.

Reopen if I'm missing something and there is something we can actually do.

Note: See TracTickets for help on using tickets.