psas / stm32

PSAS STM32F4xx firmware development.
30 stars 20 forks source link

Investigate `make_addr` with anonymous struct #37

Closed natronics closed 10 years ago

natronics commented 10 years ago

@jameysharp sez: it should work if were using gcc and/or in c99 mode.

jameysharp commented 10 years ago

The following test program doesn't give me any warnings or errors when compiled with gcc -Wall -std=c99 -S test.c.

#include <netinet/in.h>

#define make_addr(port, addr) (const struct sockaddr *) &(const struct sockaddr_in){ \
        .sin_family = AF_INET, \
        .sin_port = (port), \
        .sin_addr = { (addr) } }

const struct sockaddr *addr = make_addr(12, 0x7F000001);

void test(void)
{
        connect(-1, make_addr(1234, 0x7F000001), sizeof(struct sockaddr_in));
}