Thread: CFile error

  1. #1
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607

    CFile error

    I'm trying to open a CFile using this code:

    Code:
    ...
        CFile file;
        CFileException fileex;
        TCHAR cause[1024];
    
        BOOL result=file.Open(dlg->GetPathName(),
                              CFile::modeCreate || CFile::modeNoTruncate ||  
                              CFile::modeWrite, &fileex);
    
        if (result==0)
        {
          fileex.GetErrorMessage(cause,1024);
    
          CString errorText;
          errorText.Format("Could not open file\n %s",cause);
    
          ::MessageBox(0,errorText,"ERROR",MB_ICONEXCLAMATION);
          return;
        }
    ...
    I get an internal compiler error number C1001. All optimizations are turned off for the debug version. This is happening in MSVC 6.

    Either way the file is not being opened because it says it cannot find it. However if you notice I use CFile::modeCreate which should create the file regardless if it exists or not.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > CFile::modeCreate || CFile::modeNoTruncate
    I think you're using the wrong kind of 'or'
    Use the bitwise |, not the logical ||
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    OMG.

    I can't believe I didn't catch that.

    What a noob error.

  4. #4
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    It's because of the double colons (:: ) everywhere.

    See? This is why I don't get into C++.

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Well it really threw the compiler off. It couldn't even recover enough to tell me what the error was except for internal compiler error C1001.

    It also threw the heap off, the stack off and several other things as well.
    I couldn't believe that all this could happen from 1 error like that. Even when it would compile w/o having CFile::modeNoTruncate, the CFile class still acted very weird as well as the CArchive class.

    When I would attempt to close the archive, it would assert horribly in release and debug versions, but it was inside of crtdebug.h which was ....um....not good.

    Sometimes even in the new MSVC 05 .NET it is still very hard to trace errors because the debugger constantly shows code that is not yours. I'm not sure if there is a way to prevent this since a programmer could cause an assertion in MSVCRT and in Kernel32.DLL due to improper use.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM