[ECOS] max() confusion. (was [SMP]serious bug...)

Sergei Organov osv@topconrd.ru
Fri Dec 3 14:33:00 GMT 2004

sandeep <shimple0@yahoo.com> writes:
> btw, looking at the end of compat-posix-tm_basic test, in function
> main, there is code like
> // Sanity
>   ntest_threads = max(512, ntest_threads);
> .....
> #else
>   ntest_threads = max(64, ntest_threads);
> .....
> #endif
> that means, in either of then/else case, previous assignments like
>  "ntest_threads = NTEST_THREADS;"
> that set ntest_threads to user desired value (via NTEST_THREAD macro) become
> effectless. rather giving any value to that macro becomes meaningless.
> same is true for some other variables (and associated macros) there.
> is this also some leftover of earlier debugging efforts?

No, it's kinda code obfuscation, I'm afraid. Take a look at the
definition of the macro max() at the beginning of the file:

#ifndef max
#define max(n,m) (m > n ? n : m)

Here you get macro max() returning minimum (surprise!) of its arguments.
Thus, the statements you mentioned effectively limit the maximum values
of the parameters (that's why the max() macro is called 'max' there, I
guess) by calculating minimum of the two arguments.

Worse yet, the max() definition is under #ifndef that means that if
somehow usual 'max' definition gets included into the file, the meaning
of the statements you've noticed would change to the opposite.

To fix all that, just search-and-replace 'max(' by 'min(' in the file.

The same problem exists in the kernel/current/tests/tm_basic.cxx.


Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

More information about the Ecos-discuss mailing list