stdin in Visual Studio 2005 vs. 2003

This is a discussion on stdin in Visual Studio 2005 vs. 2003 within the C Programming forums, part of the General Programming Boards category; I've been given a project to recompile quite a bit code in Visual Studio 2005 which was previously working in ...

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    3

    stdin in Visual Studio 2005 vs. 2003

    I've been given a project to recompile quite a bit code in Visual Studio 2005 which was previously working in 2003. Here's a snippet of code from a .h file that I'm having trouble with:

    #include <stdio.h>
    EXTERN FILE *fld_in
    #ifdef __MAIN__
    = stdin
    #endif /* __MAIN__ */
    ;

    EXTERN FILE *fld_out
    #ifdef __MAIN__
    = stdout
    #endif /* __MAIN__ */
    ;

    This was working fine in 2003, but in 2005 I get this error: "error C2099: initializer is not a constant" for stdin and stdout. Does anyone know what has changed between the two and how it should be done in 2005?

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,820
    What is this supposed to do?
    Extern declarations aren't supposed to be initialized...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It's probably an internal change in the header-file, so that stdin is no longer something that can be assigned a value. What has changed, I don't know.

    To me, it doesn't seem too excessive to just add the two lines to initialize fld_in and fld_out inside main, e.g.

    Code:
    int main()
    {
        ...
        fld_in = stdin;
        fld_out = stdout;
        ...
    --
    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.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Elysia View Post
    What is this supposed to do?
    Extern declarations aren't supposed to be initialized...
    I suspect that EXTERN is also changing depending on some defined macro like __MAIN__

    --
    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
    Registered User
    Join Date
    Jun 2008
    Posts
    3
    Thanks for the quick reply guys. Its not too excessive to add the initialization into main, but this is a .h file that gets compiled into a .lib and is used in I don't know how many places in the thousands of lines of code and numerous .exe files that I have to recompile. This is part of a huge system that's been around quite some time and had been compiled in every version of VS that I know of. I'm not the resident C guru of the company, but he's quite busy and I don't see him that often, so I just wanted to throw this out there to see if anyone knew of a reason something like this would have changed between the two versions. I really appreciate your replies and advice! Right now is seems that it means more work for me to figure out all the places where this crap is actually used!

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,820
    The reason was due to that it's forbidden in the standard. 2005 is more standards compliant.
    Whoever wrote it shouldn't have been doing it in the first place.
    If it's a library (dll), then put the code in DllMain.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 09:43 AM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21