Re: [xml] Simple Element+Attribute Lookup with XPath - performance ?



On 7/17/08, Volker Grabsch <vog notjusthosting com> wrote:
 for(int i=0, e=xpo->nodesetval->nodeNr; i<e; ++i) {
   xmlChar* p_val = xmlGetProp(xpo->nodesetval->nodeTab[i], "id");
   if(p_val && 0==strcmp("4", p_val)) {

Please note that in C the order of execution of

   p_val

and

   0==strcmp("4", p_val)

is not specified! Some compilers could generate code that
checks the second condition first, which could lead to a
segmentation fault or similar.

Absolutely not true.

As per K&R, section 2.6:

"More interesting are the logical operators && and ||. Expressions
connected by && or || are evaluated left to right and evaluation stops
as soon as the truth or falsehood is known. Most C programs rely on
these properties."

If your compiler checks the second condition first, it's badly broken,
and you need to talk to your vendor.

The order in which function arguments are evaluated, however, is not
specified, eg, the results of:

i=1;
foo(++i,++i);

are implementation dependant.

You may have been thinking of this point.

Steve



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]