avrdudes / avr-libc

The AVR-LibC package provides a subset of the standard C library for AVR 8-bit RISC microcontrollers.
https://avrdudes.github.io/avr-libc/
Other
261 stars 56 forks source link

definition of `sig_atomic_t` in `signal.h` #979

Closed seplog closed 2 months ago

seplog commented 2 months ago

Hey,

I think I've found a small bug in the definition of sig_atomic_t. Try this code example and it never compiles:

// File fun_signal.c
#include <signal.h>

sighandler_t signal( int signum, sighandler_t handler ) {
    ( ( void ) signum );
    // do nothing
    return handler;
}

// File main.c
#include <signal.h>
#include <stdlib.h>

#define SIGERR ( 13 )

void err_handler( int num ) {
    ( ( void ) num );
    exit( EXIT_FAILURE );
}

int main( void ) {
    signal( SIGERR, err_handler );

    return EXIT_SUCCESS;
}

compile for example with:

$ avr-gcc -mmcu=atmega328p fun_signal.c main.c                               
/usr/libexec/gcc/avr/ld: /tmp/ccA4lgNc.o:(.bss+0x0): multiple definition of `sig_atomic_t'; /tmp/ccCDOhhx.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status

To solve the problem, sig_atomic_t must defined correctly.