Browse Source

Declare globals as extern in headers, and define in source file

Otherwise, each source file that includes the header gets its own
definition, and according to the C standard (C99 6.9p5):

> If an identifier declared with external linkage is used in an
> expression (other than as part of the operand of a sizeof operator
> whose result is an integer constant), somewhere in the entire
> program there shall be exactly one external definition for the
> identifier

Most compilers use the .bss section for zero data, but if it uses
.data instead, or if -Wl,--warn-common is used, this will cause a
linking error.
tags/1.0p1
Michael Forney 3 weeks ago
parent
commit
f4b0d09e3f
Signed by: C. McEnroe <june@causal.agency> GPG Key ID: CEA2F97ADCFCD77C
4 changed files with 13 additions and 5 deletions
  1. +2
    -0
      bounce.c
  2. +5
    -5
      bounce.h
  3. +3
    -0
      client.c
  4. +3
    -0
      state.c

+ 2
- 0
bounce.c View File

@@ -41,6 +41,8 @@

#include "bounce.h"

bool verbose;

static void hashPass(void) {
char *pass = getpass("Password: ");
byte rand[12];

+ 5
- 5
bounce.h View File

@@ -110,7 +110,7 @@ static inline const char *capList(enum Cap caps) {
return buf;
}

bool verbose;
extern bool verbose;

void ringAlloc(size_t len);
void ringProduce(const char *line);
@@ -134,8 +134,8 @@ void serverSend(const char *ptr, size_t len);
void serverFormat(const char *format, ...)
__attribute__((format(printf, 1, 2)));

char *clientPass;
char *clientAway;
extern char *clientPass;
extern char *clientAway;
struct Client *clientAlloc(struct tls *tls);
void clientFree(struct Client *client);
bool clientError(const struct Client *client);
@@ -146,8 +146,8 @@ void clientFormat(struct Client *client, const char *format, ...)
size_t clientDiff(const struct Client *client);
void clientConsume(struct Client *client);

bool stateNoNames;
enum Cap stateCaps;
extern bool stateNoNames;
extern enum Cap stateCaps;
void stateLogin(
const char *pass, bool sasl, const char *plain,
const char *nick, const char *user, const char *real

+ 3
- 0
client.c View File

@@ -30,6 +30,9 @@

#include "bounce.h"

char *clientPass;
char *clientAway;

static size_t active;

enum Need {

+ 3
- 0
state.c View File

@@ -25,6 +25,9 @@

#include "bounce.h"

bool stateNoNames;
enum Cap stateCaps;

typedef void Handler(struct Message *msg);

static void require(const struct Message *msg, bool origin, size_t len) {

Loading…
Cancel
Save