ByteJuggler 45 Posted July 12, 2019 (edited) I have an irritating hint that I'm trying to get rid of ("warning W1036: Variable 'xxx' might not have been initialised" or with initialisation supplied and with project options disabling Assertions the same block of code emits "Value assigned to 'xxx' never used".) The root of the problem is that there's an initializing assignment which sets a variable to zero, followed by some logic, followed by an Assert that checks against the variable. The trouble happens because of the different "Assert" compiler option in force between RELEASE and DEBUG. Under DEBUG mode (for this particular project) "Assertions" are set to True, which means during compilation the Assert() line is not elided (removed), and the compiler therefore (correctly) demands (hints) that the variable being asserted against should be initialised with the first message if not done. Obviously adding an initialising line fixes the hint for DEBUG mode. However, if you then compile the same code in RELEASE mode (for which "Assertions" are set to False), then the Assert() line is elided during compilation. This means the variable initialization is now redundant and then the result is the compiler hint "Value assigned to 'xxx' never used", which (correctly) demands that the initialisation line should be removed. The question is essentially how to fix this so the code can compile successfully without hints both with DEBUG and with RELEASE settings, e.g. both with Assertions enabled and disabled. More concretely, the implication of the above is that to fix this, the initialization code must be conditional and somehow only be included only when assertions are enabled and omitted/removed otherwise, since the initialization is required only if the Assert() check is going to be done. Hence the title of this post and my question: Does anyone know of a compiler directive or something to detect whether assertions are active that will allow me to correctly condition the inclusion of the initialisation assignment so as to eliminate this hint both when Assertions are enabled and disabled? Edited July 12, 2019 by ByteJuggler Share this post Link to post
David Heffernan 2345 Posted July 13, 2019 This information is documented http://docwiki.embarcadero.com/RADStudio/Rio/en/Delphi_Compiler_Directives_(List)_Index 1 Share this post Link to post
ByteJuggler 45 Posted July 13, 2019 14 hours ago, Uwe Raabe said: Did you try this? {$IFOPT C+} I haven't, thanks. I'll try it Monday. (Seems a facepalm is incoming.) Thanks again. 🙂 Share this post Link to post
ByteJuggler 45 Posted July 13, 2019 14 hours ago, David Heffernan said: This information is documented http://docwiki.embarcadero.com/RADStudio/Rio/en/Delphi_Compiler_Directives_(List)_Index You are of course correct. Thanks. I should've looked and thought harder before posting. 1 Share this post Link to post