A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 4 years ago

So I heard the #include directive in C/C++ can include virtually any text file, whether it be .h, .c, .txt, etc. Is it good to include the .c/.cpp sources in your files instead of the headers?

  • This Question is Closed
  1. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    so my main.c will consist solely of #include's, #define's, and #pragma's and other weird directives (possible macros, etc)... and I will have an my_algorithms.c, a my_data.c (which will #include some .txt files itself), and my_game.c which will be the game engine.

  2. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    http://ideone.com/ljAXA

  3. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Or is this the WRONG way to build a large program? :(

  4. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    While it is allowed to include the .c files in a #include statement, it is considered bad practice. It can be useful for certain performance related code, it can become make maintenance of the code difficult in the long run.

  5. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Also this can cause builds to fail because many environements assume that each .c file will create one object file. This can lead to you having problems linking.

  6. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    It's legal but has all kinds of problems. For example, static variables or functions in one of the source files (statics are supposed to be known only in the scope of the file that they're declard in) are sudddenly known throughout your entire program. There are other examples of why this is bad. It'll also lead to enormous build times. Change one thing in one of the files, the preprocessor will include them all into one big file and you're essentially always doing a full rebuilt. So long story short, yes - this is absolutely the wrong way. :P

  7. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.