2

I have a class which I'm serialising to send over a unix socket and it has to have a string which I've stored as a char array. Can I initialise it in the constructor differently to how I've done it here?

typedef struct SerialFunctionStatus_t {
    SerialFunctionStatus_t() 
        : serial_rx_count(0), serial_tx_count(0), socket_rx_count(0), socket_tx_count(0) 
        { port[0] = '\0'; }
    uint32_t serial_rx_count;
    uint32_t serial_tx_count;
    uint32_t socket_rx_count;
    uint32_t socket_tx_count;
    char port[20];
} SerialFunctionStatus_t;
2
  • In C++, you don't need the "typedef". Commented Oct 29, 2008 at 2:41
  • Thanks for that BKB. Can you tell I'm really a C programmer? Commented Oct 31, 2008 at 6:12

1 Answer 1

7

Put port() in the initializer list. This causes port to be 'value initialized' (12.6.2), which for arrays of builtins means zero initialized (8.5).

Sign up to request clarification or add additional context in comments.

1 Comment

What are you talking about? port() is not in the initializer list. Or did he edit his post?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.