I have the folthiwing header file:
/* bin_sort_and_search.h */
#ifndef BIN_SORT_AND_SEARCH_H_INCLUDED
#define BIN_SORT_AND_SEARCH_H_INCLUDED
void quick_sort_hoare(FILE *file);
int find_entry_with_binary_search(
FILE *file, const char *file_name, const char *entry_name
);
#endif
If its body bin_sort_and_search.c
starts with
/* bin_sort_and_search.c */
#include "bin_sort_and_search.h"
#include <stdio.h>
/* ... */
I get
error: unknown type name ‘FILE’
If I start it with
/* bin_sort_and_search.c */
#include <stdio.h>
#include "bin_sort_and_search.h"
/* ... */
or include stdio.h
in my header file, everything will be fine.
I completely understand that this is due to the need for the type definition to precede any use of the type.
But doesn’t it contradict the concept of incomplete types?
I pre-defining a function header with an as-yet-unknown type, but does that really matter – the variable’s address is always the same size, so it can be found later.
Why doesn’t this work in practice?