#include in .ho .c / .cpp?
Durante la codifica in C o C++, dove dovrei avere il #include
è?
richiamata.h:
#ifndef _CALLBACK_H_
#define _CALLBACK_H_
#include <sndfile.h>
#include "main.h"
void on_button_apply_clicked(GtkButton* button, struct user_data_s* data);
void on_button_cancel_clicked(GtkButton* button, struct user_data_s* data);
#endif
richiamata.c:
#include <stdlib.h>
#include <math.h>
#include "config.h"
#include "callback.h"
#include "play.h"
void on_button_apply_clicked(GtkButton* button, struct user_data_s* data) {
gint page;
page = gtk_notebook_get_current_page(GTK_NOTEBOOK(data->notebook));
...
Tutti gli include dovrebbero essere in .ho .c / .cpp, o entrambi come ho fatto qui?
Risposte:
Metti quanto più puoi nel .c
e il meno possibile nel .h
. Include nel .c
sono inclusi solo quando quel file viene compilato, ma include per .h
devono essere inclusi da ogni file che lo utilizza.
Alcune risposte al codice
#ifndef _CALLBACK_H_ #define _CALLBACK_H_ #include <sndfile.h>
#include "main.h" void on_button_apply_clicked(GtkButton* button, struct user_data_s* data);
void on_button_cancel_clicked(GtkButton* button, struct user_data_s* data);
#endif
#include <stdlib.h>
#include <math.h>
#include "config.h" #include "callback.h" #include "play.h" void on_button_apply_clicked(GtkButton* button, struct user_data_s* data) { gint page;
page = gtk_notebook_get_current_page(GTK_NOTEBOOK(data->notebook));
...
#ifndef MY_HEADER_H #define MY_HEADER_H #include <stdio.h>
void doStuffWith(FILE *f);
// need the definition of FILE from stdio.h #endif