While trying to create a socket connection to my port I encounter the following warning from CLion
Clang-Tidy: Uninitialized record type: 'server_address'
Here is my code:
#include <iostream>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
int main() {
const int server_socket = socket(AF_INET, SOCK_STREAM, 0);
if (server_socket == -1) {
std::cerr << "Socket creation error" << std::endl;
return EXIT_FAILURE;
}
struct sockaddr_in server_address;
server_address.sin_family = AF_INET;
server_address.sin_port = htons(8080);
server_address.sin_addr.s_addr = INADDR_ANY;
if (bind(server_socket, reinterpret_cast<struct sockaddr *>(&server_address), sizeof(server_address)) < 0) {
std::cerr << "Socket to port binding error" << std::endl;
return EXIT_FAILURE;
}
std::cout << "server is running and bound to port 8080" << std::endl;
close(server_socket);
return EXIT_SUCCESS;
}
I don’t really know what to do about it since I am not familiar with CLang-Tidy
>Solution :
Add curly braces after declaring server_address like this (you can also drop "struct" from the start of that line because you aren’t defining a new struct.):
sockaddr_in server_address{};
Or you can ignore it, since you’re initializing it in the lines right after that.
And here’s a similar question with some more info if you’re curious: Clion Unintialized record type: player