Thread: Avoiding Global variables

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by matsp View Post
    Why not - Visual Studio (all versions, including 2008) can compile C code. Presumably you are either using C++ features, or something else is wrong in your code... What error(s) do you get?

    --
    Mats
    I just renamed the .cpp file to .c and hit compile, I get a pre-compile header error... turning them of gives billion errors

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by csonx_p View Post
    I just renamed the .cpp file to .c and hit compile, I get a pre-compile header error... turning them of gives billion errors
    Yeah, you probably need to do a clean before you build (rebuild all or whatever it's called in MS speak), as the precompiled headers will "know" whether you are using C++ or C when compiling the header, so if you just rename the file, it will still think the precompiled header is the same [my personal opinion is that precompiled headers are only worth-wile in big projects - in small projects the saving is pretty small, really].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by matsp View Post
    Yeah, you probably need to do a clean before you build (rebuild all or whatever it's called in MS speak), as the precompiled headers will "know" whether you are using C++ or C when compiling the header, so if you just rename the file, it will still think the precompiled header is the same [my personal opinion is that precompiled headers are only worth-wile in big projects - in small projects the saving is pretty small, really].

    --
    Mats
    Visual Studio 2005 compiles well if you add a c file but as console application, once you choose windows application then is a problem.... Is there a step by step on how to compile windows application with .c files?

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by csonx_p View Post
    Visual Studio 2005 compiles well if you add a c file but as console application, once you choose windows application then is a problem.... Is there a step by step on how to compile windows application with .c files?
    It shouldn't be a problem. But seeing as I don't have MSVC (well, I have V6.0 on my machine, but I don't use it, and it would probably be quite different from 2005 anyways) here at work, I can't really help.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Quote Originally Posted by matsp View Post
    [my personal opinion is that precompiled headers are only worth-wile in big projects - in small projects the saving is pretty small, really].
    First thing I turn off in new projects, usually in the wizard, or first thing if the wizard wont let me (win32 projects). The savings even on large projects are negligiable. I have one project that has 100,000 lines of code in ~100 files, each including ~5 headers. It takes about 2 minutes to compile with PCH and 2 minutes 30 seconds without. I dont honestly see the point. I suppose if you had millions of lines of code and tens of thousands of #include's it migth make a bigger difference, but again, whats the point, you will still be compiling for an hour.

    IMO they woudl get better performance by multithreading the compile. FileA can be compiled in parallel with FILEB, the linker stage would probably still need to be serial, but not compilation.
    Last edited by abachler; 05-15-2008 at 09:17 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 08-06-2008, 09:59 AM
  2. global variables
    By shadovv in forum C++ Programming
    Replies: 7
    Last Post: 10-24-2005, 02:21 PM
  3. global variables - okay sometimes...?
    By MadHatter in forum C++ Programming
    Replies: 21
    Last Post: 01-21-2003, 04:23 PM
  4. global variables
    By rdnjr in forum Linux Programming
    Replies: 0
    Last Post: 01-07-2003, 10:28 AM
  5. Global variables? Bad! Yes, but to what extent?
    By Boksha in forum C++ Programming
    Replies: 6
    Last Post: 05-26-2002, 04:37 PM