#over optimizing

2 messages · Page 1 of 1 (latest)

quartz perch
#

I am tryng to optimize the code even further but I can't think of a way to do that except code it in x86 direclty.
Note that this code is just for testing ,the malloc , free and printf are here for -O3 to not remove the unused parts and I plan on tranfering the main to a sperated function to return the malloced structure

#include <stdio.h>
#include <fcntl.h>
#include <CHK.h>

typedef struct s_Settings{
   bool a;
   bool b;
}*Settings;

int main() {
    int file_point = open("./test.txt",O_RDONLY,0666);
    CHK(file_point);
    Settings out = malloc(sizeof(struct s_Settings));
    char buff[2];
    read(file_point,buff,2);
    out->a = buff[0];
    out->b = buff[1];
    close(file_point);
    printf("%d%d",out->a,out->b);
    free(out);
    return 0;
}

//CHK.h
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>

#define CHK(op) do { if ((op) == -1) message (1, #op); } while (0)

void message(int syserr, const char *msg, ...);

//CHK.c
void message(int syserr, const char *msg, ...) {
    va_list ap;
    va_start (ap, msg);
    vfprintf(stderr, msg, ap);
    fprintf(stderr, "\n");
    va_end (ap);

    if (syserr == 1)
        perror("");

    exit(EXIT_FAILURE);
}
clear portalBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.