Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C-fags

Name: Anonymous 2011-06-25 16:08

What would be the best way to implement flags in C?
Bit-fields, enums, defines, etc. I've seen arguments for all three so I'm asking you, mighty /prog/, to resolve this problem.

inb4 every /prog/ meme in existence

Name: Anonymous 2011-06-25 20:26


/* anus.h
 */
#ifndef ANUS_H__
#define ANUS_H__

enum {
    ANUS1 = (1 << 0),
    ANUS2 = (1 << 1),
    ANUS3 = (1 << 2),
    ANUS4 = (1 << 3)
};

char *hax(int);

#endif /* ANUS_H__ */


/* anus.c
 */
#include <stdio.h>
#include <stdlib.h>

#include "anus.h"

char *hax(int anii) {
    char *s;

    if (!(s = malloc(20)))
        return "back to the imageboards";

    sprintf(s, "%s%s%s%s",
               anii & ANUS1 ? "=__= " : "",
               anii & ANUS2 ? "^__^ " : "",
               anii & ANUS3 ? "v__v " : "",
               anii & ANUS4 ? "-__-" : "");

    return s;
}


/* main.c
 */
#include <stdio.h>

#include "anus.h"

int main(void) {
    puts(hax(ANUS4 | ANUS2));

    return 0;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List