APPFS
Advanced practical programming for scientists
|
Appfs Exercise 1: direct read input, big endian is handled, use of int32_t and uint32_t. More...
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <assert.h>
Go to the source code of this file.
Macros | |
#define | MAX_NUMS ((INT32_MAX >> 5) + 1) |
Maximum number of 32 bit ints we need to store bits. More... | |
#define | BUF_NUMS 4096 |
read buffer size More... | |
Functions | |
static bool | is_little_endian (void) |
Check if the architecture is little endian. More... | |
static int32_t | reverse_int32 (int32_t val) |
Reverse the 4 bytes of an int between little and big endian. More... | |
int | main (int argc, char **argv) |
Program to read a file with binary positive 32 bit integers, sort the numbers and print them sorted. More... | |
gcc -O3 -Wall -std=c99 -o ex1a2 ex1a2.c
Using direct read() for input Improvements to ex1a: big endian is handled, use of int32_t and uint32_t. Adding of static inline.
Definition in file ex1a2.c.
|
inlinestatic |
This check is constant and can be optimized away by the compiler during compile time. All conditionals depending on it are then decided at compile time
int main | ( | int | argc, |
char ** | argv | ||
) |
Actually, the numbers are not sorted. There is an array with one bit for each possible number. Upon reading the respective bit is set for the number recognized. At the end the array is scanned in order and the numbers present are printed.
argv | [1] name of file to read |
Definition at line 58 of file ex1a2.c.
|
inlinestatic |