1. Unter "Exception Handling and CRT Linkage"
Ich habe eine CRT statische library und mein Programm linked zu dieser library, auch mit statischer CRT. Also was soll man tun wenn CRT statisch ist?
Man soll /NODEFAULTLIB angeben. Warum? Ich verstehe den Sinn nicht ganz.
Muss ich jetzt in der library auch den Code einfügen oder benutzen diese die gemeinsame CRT weil beide statisch sind?
2. Wie genau funktionieren die Floating Point exceptions?
http://www.devx.com/cplus/Article/34993/1954
hier wird ja gezeigt, wie man sie enabled. Nur muss ich sie enablen und zusätzlich fp:except beim Compiler angeben? Oder wie beeinflusst sich das gegenseitig. Auch der Rest des Artikels ist mir nicht ganz klar, wenn ich signals verwende (SIGFPE) muss ich sie trotzdem wie in diesem Artiekl enablen aber ich brauch keine C++ / SEH mixed exceptions ?
Zu 1:
Das mit NODEFAULTLIB verstehe ich auch nicht. Allerdings ist statisches linken bei mehreren Modulen einfach Schrott. Das Problem ist dass Du in jedem Moudl, dan die Exceptions selbst behandeln musst und in jedem Modul einen eigenen Exception Handler benötigst.
Hast die die CRT als DLL könne alle Module sich das Exception Handling teilen... egal in welchem Modul es ist.
Auch wenn hier viele immer wieder sagen: Staisches Linken ist das Beste, halte ich wenig davon, wenn ich mehr als ein Modul habe. Dann würde ich immer die CRT als DLL-Version benutzen.
Hmm warum selbst behandeln? Wenn ich aus meinem Hauptprogramm eine Funktion aus meiner Library aufrufe (die statisch gelinkt ist) und in dieser eine Exception geworfen wird, kommt sie auch am Hauptprogramm an beim catch. Also wie gesagt library und Hauptprogramm bilden dann eine exe. Oder meinst du dass ich dann in der Library die CRT handler auch setze müsste?
zu 2. vielleicht interessiert es wen, es scheint komplett egal zu sein ob die compiler option gesetzt ist oder nicht
/*
//Set the x86 floating-point control word according to what
//exceptions you want to trap.
_clearfp(); //Always call _clearfp before setting the control
//word
//Because the second parameter in the following call is 0, it
//only returns the floating-point control word
unsigned int cw;
_controlfp_s(&cw, 0, 0); //Get the default control
//word
//Set the exception masks off for exceptions that you want to
//trap. When a mask bit is set, the corresponding floating-point
//exception is //blocked from being generating.
cw &=~(EM_OVERFLOW|EM_UNDERFLOW|EM_ZERODIVIDE|
EM_DENORMAL|EM_INVALID);
//For any bit in the second parameter (mask) that is 1, the
//corresponding bit in the first parameter is used to update
//the control word.
unsigned int cwOriginal;
_controlfp_s(&cwOriginal, cw, MCW_EM); //Set it.
//MCW_EM is defined in float.h.
//Restore the original value when done:
//_controlfp(cwOriginal, MCW_EM);
*/ float a = 1;
float b = 0;
float c = a/b;
std::cout << c;
/*
//Set the x86 floating-point control word according to what
//exceptions you want to trap.
_clearfp(); //Always call _clearfp before setting the control
//word
//Because the second parameter in the following call is 0, it
//only returns the floating-point control word
unsigned int cw;
_controlfp_s(&cw, 0, 0); //Get the default control
//word
//Set the exception masks off for exceptions that you want to
//trap. When a mask bit is set, the corresponding floating-point
//exception is //blocked from being generating.
cw &=~(EM_OVERFLOW|EM_UNDERFLOW|EM_ZERODIVIDE|
EM_DENORMAL|EM_INVALID);
//For any bit in the second parameter (mask) that is 1, the
//corresponding bit in the first parameter is used to update
//the control word.
unsigned int cwOriginal;
_controlfp_s(&cwOriginal, cw, MCW_EM); //Set it.
//MCW_EM is defined in float.h.
//Restore the original value when done:
//_controlfp(cwOriginal, MCW_EM);
*/ float a = 1;
float b = 0;
float c = a/b;
std::cout << c;
/*
//Set the x86 floating-point control word according to what
//exceptions you want to trap.
_clearfp(); //Always call _clearfp before setting the control
//word
//Because the second parameter in the following call is 0, it
//only returns the floating-point control word
unsigned int cw;
_controlfp_s(&cw, 0, 0); //Get the default control
//word
//Set the exception masks off for exceptions that you want to
//trap. When a mask bit is set, the corresponding floating-point
//exception is //blocked from being generating.
cw &=~(EM_OVERFLOW|EM_UNDERFLOW|EM_ZERODIVIDE|
EM_DENORMAL|EM_INVALID);
//For any bit in the second parameter (mask) that is 1, the
//corresponding bit in the first parameter is used to update
//the control word.
unsigned int cwOriginal;
_controlfp_s(&cwOriginal, cw, MCW_EM); //Set it.
//MCW_EM is defined in float.h.
//Restore the original value when done:
//_controlfp(cwOriginal, MCW_EM);
*/ float a = 1;
float b = 0;
float c = a/b;
std::cout << c;
wenn der Code auskommentiert ist funktionieren float exceptions nicht, wenn er da ist funktionieren sie, egal wie die Compiler Option eingestellt ist.
Wie ich das verstehe sorgt fp:except dafür, dass nach jeder Gleitkoma-Operation eine Exception geworfen werden kann. Die FPU kann aber mehrere Gleitkomma Operationen auf einmal ausführen. Ist fp:except nicht gesetzt wird erst nach einer Gruppe von Gleitkommaoperationen die fehlgeschlagen ist eine Exception geworfen. Mit fp:except geschieht dies exakt nach der Operation die fehlgeschlagen ist.
fp:except hat nichts mit der "allgemeinen Fähigkeit" von Gleitkomma-Exceptions zu tun.
So ist zumindest meine Interpretation was ich dazu lese...
was ich aber noch nicht ganz verstehe, ist, wie ich mit der CRT umgehen soll.
Wenn ich eine .lib (statische library) erstelle und diese linke in meinem Hauptprojekt (auch statisch CRT) dann benutzen doch trotzdem beide die gleiche CRT oder? Es ist ja keine DLL und exe sondern beides wird ja in die exe compiled und müssten die gleich CRT benutzen. Dann müsste ich die CRT handler auch nur 1 mal setzen oder nicht?
Wie soll das sonst gehen? Ein .lib kann sich ja keinen CRT handler setzen, weil alle Funktion die ich aus der lib aufrufe im Kontext des Hauptprogrammes sind.
Nächstes Thema anzeigen Vorheriges Thema anzeigen
Sie können Beiträge in dieses Forum schreiben. Sie können auf Beiträge in diesem Forum antworten. Sie können Ihre Beiträge in diesem Forum nicht bearbeiten. Sie können Ihre Beiträge in diesem Forum nicht löschen. Sie können an Umfragen in diesem Forum nicht mitmachen.
c++.de ist Teilnehmer des Partnerprogramms von Amazon Europe S.à.r.l. und Partner des Werbeprogramms, das zur Bereitstellung eines Mediums
für Websites konzipiert wurde, mittels dessen durch die Platzierung von Werbeanzeigen und Links zu amazon.de
Werbekostenerstattung verdient werden kann.
Die Vervielfältigung der auf den Seiten www.c-plusplus.de, www.c-plusplus.info, www.c-sar.de, www.c-plusplus.net und www.baeckmann.de
enthaltenen Informationen ohne eine schriftliche Genehmigung des Seitenbetreibers ist untersagt
(vgl. §4 Urheberrechtsgesetz). Die Nutzung und Änderung der vorgestellten Strukturen und Verfahren in
privaten und kommerziellen Softwareanwendungen ist ausdrücklich erlaubt, soweit keine Rechte Dritter verletzt werden.
Der Seitenbetreiber übernimmt keine Gewähr für die Funktion einzelner Beiträge oder Programmfragmente, insbesondere
übernimmt er keine Haftung für eventuelle aus dem Gebrauch entstehenden Folgeschäden.