开发者

What is more efficient with C code?

What is more efficient with the C code I am working with, moving my code into an existing C program or have an h file #included so it calls the separate .c file?

When this is compiled into an .exe how does this work with having it incorporated into the original code vs having an h file and separate .c file?

I am not sure how many lines of code the program has开发者_运维问答 which I would incorporate this other code into but my code is only about a thousand lines of code.

Thanks, DemiSheep


There's no difference in efficiency between keeping code in a single .c file or in multiple .c files linked into the same executable, since once the executable is created, chances are it will contain the same binary code whichever method you choose. This can be easily verified with a binary disassembler, of course.

What a single .c file can change, however, is the speed of compilation, which may be faster for a single file than for a bunch of files that have to be linked together. IIRC, one of the reasons SQLite's preferred source distribution method is a single huge "amalgamated C file" is compilation speed.


That said, you should really not concern yourself with issues of this kind. Do break your programs into separate modules, each with a clean interface and a separate implementation file.


I know this already has a good answer that says no difference but wanted to add this

The #include directive tells the preprocessor to treat the contents of a specified file as if those contents had appeared in the source program at the point where the directive appears.

I would have wrote it myself but the msdn docs say it quite nicely.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜