On Wednesday 17 June 2026 19:55:43 Pali Rohár wrote:
> On Wednesday 17 June 2026 06:39:01 Kirill Makurin wrote:
> > Pali Rohár <[email protected]> wrote:
> > > I would propose to call this function at the beginning of main() before
> > > declaring or initializing any variable, to ensure that it is always
> > > called at the beginning. Initialization of variable could be done by
> > > function call which could potentially cause assert/failure.
> > 
> > I'm certain that I made sure that in every test which calls 
> > `mingw_test_init`, this it is the first function called.

Now I have figured out that the test t_excpt_int_divzero.c does not do
it for arm target. It does not call mingw_test_init at all.

> Ok. If it was correctly checked/reviewed I'm not going to oppose it.
> But it does not have to be so obvious for new developer who is going to
> read the code.
> 
> And lot of people are writing new tests by copying some existing and
> modifying it (old test is used as a template). And this can cause an
> issue because if modifying existing code, people can forgot about the
> fact that adding a new variable with initialization from function is
> forbidden for main.
> 
> So I think it is safer to put the mingw_test_init immediately after the
> main, that would be explicit for everybody that variables needs to be
> initialized after that call. Visually it looks like this:
> 
>   int main() {
>     mingw_test_init();
> 
>     int my_variable = some_function();
>     int ret = 0;
> 
>     ...
> 
>     return ret;
>   }
> 
> > I wasn't sure whether I should call `mingw_test_init` before declaration 
> > block. My guess was that the declaration block like this is used or allow 
> > code to compile in strict C89 mode, which does not support mixing 
> > declarations and code. So, I tried to keep it whenever possible.
> 
> mingw-w64 already requires GNU extensions and calling functions before
> declaration block is in this case allowed.
> 
> But you are right that in strict non-GNU C89 it is forbidden.
> 
> Makefile.am already contains "AM_CFLAGS=-pipe -std=gnu99" so the code is
> always compiled in GNU C99 mode and it is requirement from compiler.
> 
> IMHO for me the above code where the mingw_test_init() is called as the
> first thing immediately under "int main() {" line is more readable.


_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to