This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: max() confusion. (was [SMP]serious bug...)
- From: Sergei Organov <osv at topconrd dot ru>
- To: sandeep <shimple0 at yahoo dot com>
- Cc: Nick Garnett <nickg at ecoscentric dot com>, ecos-discuss at sources dot redhat dot com
- Date: 03 Dec 2004 17:33:06 +0300
- Subject: Re: [ECOS] max() confusion. (was [SMP]serious bug...)
- References: <20041129155659.66563.qmail@web52702.mail.yahoo.com>
sandeep <shimple0@yahoo.com> writes:
> btw, looking at the end of compat-posix-tm_basic test, in function
> main, there is code like
>
> // Sanity
> #ifdef WORKHORSE_TEST
> 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)
#endif
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.
--
Sergei.
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss