[VS 2005] Float-Zeiger braucht C-Runtime?



  • Ich hab ein bisschen rumprobiert mit dem "Mini-Code" aus diesem Thread ( zweiter Post ) http://www.c-plusplus.net/forum/viewtopic-var-t-is-201555.html

    Ich hab folgendes versucht:

    #include <windows.h>
    #pragma comment( linker, "/entry:entry" )
    
    int _stdcall hallo( int* param, float test )
    {
    	float* hi = 0;
    	*hi = 2.5f;
    
    	return 1;
    }
    
    void entry( )
    {
    	MessageBoxA( 0, "Entry", "", 0 );
    }
    

    Dann kommt immer ein Compiler-Fehler, wegen eines unaufgelösten externen Symbols ( "Verweis auf nicht aufgelöstes externes Symbol '_main' in Funktion '___tmainCRTStartup'." ). Wenn ich beim kompilieren mit der CRT linke ( /MD ) funktionierts. Oder wenn man die Zeile "*hi = 2.0f;" auskommentiert.
    Was haben die Floats mit der Runtime zu tun? Wenn man an der Stelle Ints verwendet, kommt kein Fehler. 😕



  • Ja, die CRT und der Compiler sind in einigen Dinge sehr stark verzahnt...

    Und ich muss gestehen: Ich hab absolut keine Ahnugn was "_fltused" sein soll... da es auch in der CRT *nirgend* verwendet wird 😮

    So lässt es sich aber übersetzen:

    #include <windows.h>
    #pragma comment(linker, "/entry:entry")
    #pragma comment(linker, "/nodefaultlib:libcmt")
    #pragma comment(linker, "/nodefaultlib:oldnames")
    #pragma comment(linker, "/nodefaultlib:uuid.lib")
    
    extern "C" int _fltused;
    int _fltused = 0x9875;
    
    int hallo( int* param, float test )
    {
        float* hi = 0;
        *hi = 2.5f;
        return 1;
    }
    
    void entry()
    {
      TCHAR szText[] = TEXT("Hello world\n");
      DWORD dwWritten;
      WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), szText, lstrlen(szText), &dwWritten, NULL);
      //MessageBoxA( 0, "Entry", "", 0 );
    }
    
    F:\Test\CPP_VS2005>cl /c /O1 /GS- CPP_VS2005.cpp
    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    CPP_VS2005.cpp
    
    F:\Test\CPP_VS2005>link /subsystem:console CPP_VS2005.obj kernel32.lib /entry:en
    try
    Microsoft (R) Incremental Linker Version 9.00.21022.08
    Copyright (C) Microsoft Corporation.  All rights reserved.
    


  • Vielen Dank!
    Woher hast du gewusst, dass _fltused den Fehler verursacht?



  • dumpbin /ALL obj-Datei
    


  • Ist ja interessant ...
    Dankeschön! 🙂


Anmelden zum Antworten