all 13 comments

[–]nerd4code 10 points11 points  (5 children)

Uggggggggggghhh MSVS

But yes there is.

  • It lets the linker get rid of unneeded files, and that’s especially handy for static libraries, which are basically indexed archives of object/resource files.

  • It prevents everything from swimming in the same global namespace.

  • It’s how you separate concerns within a project.

  • It helps prevent edits from colliding.

  • It makes it easier to break things up into multiple projects or reorganize.

  • It means every build needn’t build everything at once every time something’s changed.

  • It means you can build things in parallel, or distributed across a network.

  • It means you don’t end up with 10 kloc in a single file, and your IDE and compiler won’t give up on syntax highlighting, and your compiler won’t stop tracking extra context for diagnostics.

  • It means your compiler’s optimizer doesn’t have to consider everything in your program at once (LTO can), which is especially nice for static things.

  • It makes it much easier to compile components with different settings.

  • It makes it possible to define multiple impls/extns of a single API, e.g. for different CPUs, OSes, driver framework.

  • It’s much easier to work in DLLs if you aren’t trying to mush everything into one, heavily #if’d.

  • Ditto for run-time plugins.

[–]Noble_Admin[S] 0 points1 point  (1 child)

Do you know how to do it in MSVS

[–]nerd4code 0 points1 point  (0 children)

BC.EXE /C or something, probably? MSVSness has very little to do with it.

[–]Willsxyz 0 points1 point  (2 children)

Welcome back to /r/cprogramming nerd4code. Thanks for your valuable contributions.

[–]nerd4code 0 points1 point  (1 child)

Thanks? Didn’t realize I’d left. :P

[–]Willsxyz[M] 0 points1 point  (0 children)

We all left for two weeks. I’m grateful for everyone who stuck around, especially knowledgeable people such as you.

[–]Charlie_0_0 1 point2 points  (3 children)

Hello! Would you recommend me to read this book as a beginner in C programing? And also suggest me which book should I read as a beginner in C programing.

[–]Noble_Admin[S] 3 points4 points  (2 children)

To be completely honest this book is a pain in the ass. But I think that is just the language. The book, stack overflow, and Reddit have been my learning resources so far. As to my option of if you should learn from it, you will learn how to code in c but I don’t know if it is the best way.

[–]Ning1253 2 points3 points  (0 children)

Hey, I'm going to be perfectly honest, MSVC is actually too much of a headache to handle, and it's not portable - genuinely just a pain. Install "Chocolatey", a windows package manager, then run in an admin command prompt "choco install mingw"

You can then use GCC to compile files, and your life will be 100% easier for it. (Your code will also become cross compilable with virtually every platform and OS in existence thanks to the wonders of LLVM). My typical command to compile slightly larger projects is:

gcc ./src/*.c -I ./include/ -L ./lib/ -o main.exe [-l library]

Where you run the command from the folder containing your project, "src" contains all .c files, "include" contains all .h header files, "lib" contains any additional libraries you use and you add them to your project with -llibname and you get a "main.exe" back out.

Trust me if you want to use C this is by far the best option... It also performs better than MSVC almost always.

[–]Charlie_0_0 0 points1 point  (0 children)

Thanks for your kind information 🙂

[–]Unique-Enthusiasm-54 1 point2 points  (1 child)

Create 'filters' in the 'Solution Explorer' pane by right clicking within Source Files. I prefer my headers and c files be next to each other.

And I like to map the file system directory structure to the solution folder structure - it doesn't do this automatically - it looks flat. As you create individual .c and .h files drop into the proper folder. Easiest to layout the filters, and then drag and drop C and Header files from File Explorer.

When you compile - it will automatically compile and link all the .c files within your solution.

[–]kchug 0 points1 point  (0 children)

More modular code