Why are global variables bad, in a single threaded, non-os, embedded application

It wouldn’t. The two fundamental issues with global variables is simply cluttering the namespace, and the fact that “no one” has “control” over them (thus the potential collisions and conflict with multiple threads). The “globals are bad”, like pretty much every other computer programming idiom is a guideline, not a hard and fast rule. When … Read more

Is argv[n] writable?

IMO, code like argv[1] = “123”; is UB (using the original argv). “The parameters argc and argv and the strings pointed to by the argv array shall be modifiable by the program, and retain their last-stored values between program startup and program termination.” C11dr & C17dr1 ยง5.1.2.2.1 2 Recall that const came into C many … Read more

What is the difference between struct addrinfo and struct sockaddr

struct addrinfo is returned by getaddrinfo(), and contains, on success, a linked list of such structs for a specified hostname and/or service. The ai_addr member isn’t actually a struct sockaddr, because that struct is merely a generic one that contains common members for all the others, and is used in order to determine what type … Read more