Re: [xml] Error in the Tutorial

Igor Zlatkovic writes:
On 27.05.2004 02:54, John Fleck wrote:

Thanks, I'll fix that.

No, John, leave it. The code is working and I have no idea why would a 
compiler give an error here. If you want to fix it, then better do a

   xmlChar *xpath = (xmlChar*) "//keyword";

Duplicating the string here is misleading.

By the way, I cannot reproduce the error with any of the three compilers 
I have here:

Microsoft's Visual C/C++ says it isn't a big deal:

   C:\Temp>cl -Ic:\opt\fsw\include -W4 -c xpathex.c
   Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077
    for 80x86
   Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.
   test.c(37) : warning C4057: 'initializing' : 'xmlChar *' differs
    in indirection to slightly different base type from 'char [10]'

GNU C compiler doesn't say a thing. It just compiles.

   C:\Temp>gcc -Ic:\opt\fsw\include -Wall -c xpathex.c

Intel's C/C++ compiler is very conversational, but it doesn't mention 
our line 37:

   C:\Temp>icl -Ic:\opt\fsw\include -W4 -c xpathex.c
   Intel(R) C++ Compiler for 32-bit applications, Version 8.0
    Build 20031017Z
   Copyright (C) 1985-2003 Intel Corporation.  All rights reserved.
   test.c(5): remark #1418: external definition with no prior declaration
     getdoc (char *docname) {
   test.c(18): remark #1418: external definition with no prior
     declaration getnodeset (xmlDocPtr doc, xmlChar *xpath){
   test.c(55): remark #181: argument is incompatible with corresponding
     format string conversion printf("keyword: %s\n", keyword);

Note that all three compilers produced a valid object file. Also note 
that in all three cases I had to turn all possible warnings on in order 
to get any message on the screen. Finally note that only one of the 
three had mentioned the line 37 at all.

Concusion: Don't trust t-onliners. They lie. :-)

        I think you'd need a combination of high(ish) warning level
and compiler/system that treats chars as signed to get problems. In
any case, the correct solution is (as you say) to cast to xmlChar *. I
have definitely had to add such casts to placate the compiler on one
or more platforms.

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