Skip to main content
added 441 characters in body
Source Link
Harith
  • 9.8k
  • 1
  • 14
  • 50

fopen()fopen() is not required to set errno:

#if 0
    fp = fopen (filePath , "rb");

    if(!fp) {
        perror(filePath);
        exit(IO_ERR);
    }
#else
    errno = 0;
    fp = fopen(filePath, "rb");
    
    /* The cast void is required as ISO C forbids conditional expr with only one
     * void side.
     */
    if (!fp) {
        errno ? perror(filePath) : (void) fputs("Error - failed to open file.", stderr);
        exit(IO_ERR); 
    }
#endif

Use a compound literal for simplification:

As we're using C99, this:

 SourceFile sourceFile = {
        buffer,
        lSize
    };
    
return sourceFile;

can be simplified to just:

return (SourceFile) {buffer, lSize};

Does it matter if there are more than 3 arguments? Currently, the interpreter is ignoring them.

Question:

How will the user ever learn about the optional third argument? The usage message doesn't say anything about it.

fopen() is not required to set errno:

#if 0
    fp = fopen (filePath , "rb");

    if(!fp) {
        perror(filePath);
        exit(IO_ERR);
    }
#else
    errno = 0;
    fp = fopen(filePath, "rb");
    
    /* The cast void is required as ISO C forbids conditional expr with only one
     * void side.
     */
    if (!fp) {
        errno ? perror(filePath) : (void) fputs("Error - failed to open file.", stderr);
        exit(IO_ERR); 
    }
#endif

Does it matter if there are more than 3 arguments?

fopen() is not required to set errno:

#if 0
    fp = fopen (filePath , "rb");

    if(!fp) {
        perror(filePath);
        exit(IO_ERR);
    }
#else
    errno = 0;
    fp = fopen(filePath, "rb");
    
    /* The cast void is required as ISO C forbids conditional expr with only one
     * void side.
     */
    if (!fp) {
        errno ? perror(filePath) : (void) fputs("Error - failed to open file.", stderr);
        exit(IO_ERR); 
    }
#endif

Use a compound literal for simplification:

As we're using C99, this:

 SourceFile sourceFile = {
        buffer,
        lSize
    };
    
return sourceFile;

can be simplified to just:

return (SourceFile) {buffer, lSize};

Does it matter if there are more than 3 arguments? Currently, the interpreter is ignoring them.

Question:

How will the user ever learn about the optional third argument? The usage message doesn't say anything about it.

added 110 characters in body
Source Link
Harith
  • 9.8k
  • 1
  • 14
  • 50
// char* str = argv[2];
const char *str*const str = argv[2];
    /* Allocate to the referenced object, not the type. 
     * It is easier to maintain.
     */
    uint8_t *tape*const tape = malloc(tapesize * sizeof *tape);
    
    if (!tape) {
        complain();
        ..
    }

I'd expect the exit status to be EX_NOINPUT if the input file did not exist or was not readable.

// char* str = argv[2];
const char *str = argv[2];
    /* Allocate to the referenced object, not the type. 
     * It is easier to maintain.
     */
    uint8_t *tape = malloc(tapesize * sizeof *tape);
    
    if (!tape) {
        complain();
        ..
    }
// char* str = argv[2];
const char *const str = argv[2];
    /* Allocate to the referenced object, not the type. 
     * It is easier to maintain.
     */
    uint8_t *const tape = malloc(tapesize * sizeof *tape);
    
    if (!tape) {
        complain();
        ..
    }

I'd expect the exit status to be EX_NOINPUT if the input file did not exist or was not readable.

added 1 character in body
Source Link
Harith
  • 9.8k
  • 1
  • 14
  • 50
    /* Allocate to the referenced object, not the type. 
     * It is easier to maintain.
     */
    uint8_t tape*tape = malloc(tapesize * sizeof *tape);
    
    if (!tape) {
        complain();
        ..
    }
    /* Allocate to the referenced object, not the type. 
     * It is easier to maintain.
     */
    uint8_t tape = malloc(tapesize * sizeof *tape);
    
    if (!tape) {
        complain();
        ..
    }
    /* Allocate to the referenced object, not the type. 
     * It is easier to maintain.
     */
    uint8_t *tape = malloc(tapesize * sizeof *tape);
    
    if (!tape) {
        complain();
        ..
    }
added 1738 characters in body
Source Link
Harith
  • 9.8k
  • 1
  • 14
  • 50
Loading
added 129 characters in body
Source Link
Harith
  • 9.8k
  • 1
  • 14
  • 50
Loading
added 66 characters in body
Source Link
Harith
  • 9.8k
  • 1
  • 14
  • 50
Loading
added 47 characters in body
Source Link
Harith
  • 9.8k
  • 1
  • 14
  • 50
Loading
added 2 characters in body
Source Link
Harith
  • 9.8k
  • 1
  • 14
  • 50
Loading
added 437 characters in body
Source Link
Harith
  • 9.8k
  • 1
  • 14
  • 50
Loading
added 437 characters in body
Source Link
Harith
  • 9.8k
  • 1
  • 14
  • 50
Loading
added 437 characters in body
Source Link
Harith
  • 9.8k
  • 1
  • 14
  • 50
Loading
added 3152 characters in body
Source Link
Harith
  • 9.8k
  • 1
  • 14
  • 50
Loading
Source Link
Harith
  • 9.8k
  • 1
  • 14
  • 50
Loading