Import multiple libs into a single include in c

Asked

Viewed 361 times

2

Is there any way to import all libs from my program into one include as in other languages : import re, datetime, math ( Python ) ?

After reading about pre-processing directives here ( Little is said about include on this Wiki page ) I thought of something like importing the default libs from the system ( stdio, stdlib, stdbool, string, locale ... ) as external libs " stdio.h, stdlib.h ", however I think that there is no ( Or unknown ) a delimiter to put between the same so that it works properly ... just out of curiosity even if someone knows would be grateful.

In addition to the Wikipedia article : Cpp Reference Preprocessor ( Talk about the C ++ )

1 answer

2


It doesn’t exist; Preprocessor C is a very primitive macro language, and little integrated with the rest of the language (like Dennis Ritchie himself states).

What you can do is create a separate header file that includes itself all the default headers you want to include, usually called common.h or config.h:

#ifndef DEFINICOES_DE_CABECALHO
#define DEFINICOES_DE_CABECALHO

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <stdarg.h>
#include <stdint.h>
#include <time.h>
#include <locale.h>

#endif

And then, in your source files, just say

#include "common.h" // ou "config.h", ou qualquer nome que você tenha escolhido
  • 1

    Only complementing because the answer answers the question, the mechanism of Python is absurdly different from C, nor conceptually are the same thing, although it seems to a layman. even the terminology used in the question is not adequate, although it is understandable.

  • 1

    What would be the correct terminology ? - The desired primitivity of ' c ' sometimes really bothers, but that’s how it is and is powerful right ha ha

  • 2

    @bigown must be referring to the fact that libraries are not imported in C, but header files are included (that is, they are included textually in the body of the source file); these headers must declare the interface of a library, but not necessarily (can be used to implement a metaprogramming technique called X Macros, instead, for example).

  • 1

    @Exact Luissouza, that is the power of C. and Wrtmute understood correctly what I said. It may sound silly, but it has strong implications.

  • Very cool, a sim I’m abstracting my question but I have the understanding of what is imported because I recently studied Tad in ' c ', already the part of X Macros did not know vlw to inform ( I will look about )

Browser other questions tagged

You are not signed in. Login or sign up in order to post.