ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  V6.3 C++ Include File Error?
Posted by Electron Shepherd on Dec-20-2018 06:36
I've just downloaded the latest v6.3, and I'm hitting a compiler error in the new chartdir.h file, at lines 1091 and 1092. They are:

    void setResource(const char *id, MemBlock m) { return CBaseChart_setResource(ptr, id, m.data, m.len); }
    void setResource(const char *id, DrawArea *d) { return CBaseChart_setResource2(ptr, id, d->getInternalPtr()); }


Note that a void function is returning a value. In the documentation, BaseChart.setResource is a void function. I've run a diff on the v6.0 and v6.3 header files, and these lines were added as part of v6.3

If I simply remove the two 'return' keywords, everything compiles and seems to work OK.

Is this an error in the header files?

  Re: V6.3 C++ Include File Error?
Posted by Peter Kwan on Dec-20-2018 10:35
Hi Electron Shepherd,

Yes, this is an error. For some reasons, my Visual Studio does not report any error or warning. Is it possible to inform me which compiler you are using to generate the error? I am thinking, your compiler may be is more stringent and it can help us to catch this kind of error.

I will fix it within today in the distribution.

Regards
Peter Kwan

  Re: V6.3 C++ Include File Error?
Posted by Peter Kwan on Dec-20-2018 10:59
Hi Electron Shepherd,

From Google search, I found someone mentioned that a void function can return "void". I test it myself and it seems to be the case in my Visual Studio. (We also tested our code with gcc for Qt support and it seems to work too.)

For example:

void abc() { return 1; } error - void function returns a value
void abc2() { return (void)1; } // works - return is cast to "void"

int xxx() { return 1; }
void abc3() { return xxx(); } // error - void function returns a value
void abc4() { return (void)xxx(); } // works - return is cast to "void"
void abc5() { return abc2(); }  // works - return type of abc2 is "void"

The more I think, the more I feel that VS might be correct. It may have to do about templates in C++. When we write function templates, we do not know the exact data type, so sometimes we do not know whether we need to return something or not. If the C++ standard allows returning "void", it can facilitate using templates.

Anyway, I think I will still change the header files just to make it more compatible with other compilers.

Regards
Peter Kwan

  Re: V6.3 C++ Include File Error?
Posted by Peter Kwan on Dec-20-2018 14:14
Hi Electron Shepherd,

After reading more information, I now believe the original code is correct. It is legal to return a void expression.

I noticed you have not mentioned what is the error message. Is it about undefined references or symbols or something similar? Is it a compiler error, or is it a linker error? (Visual Studio should specify clear whether it is compiler or linker.)

If you use the ChartDirector 6.3 header file, but uses the "chartdir60.lib" from ChartDirector 6.0, there will be linker error. It is because the code is correct, so there should be no compiler error. However, the linker, which uses the old "chartdir60.lib", does not found the new CBaseChart_setResource or CBaseChart_setResource2 functions, so it cannot link the code and produces linker errors.

Note that the DLL and LIB or both ChartDirector 6.3 and ChartDirector 6.0 are named "chartdir60.dll". We do that so that the new DLL can become the drop in replacement of the old DLL.

If the above still cannot solve the problem, would you mind to inform me of the exact error message?

Regards
Peter Kwan

  Re: V6.3 C++ Include File Error?
Posted by Electron Shepherd on Dec-20-2018 17:18
Peter,

The error message is:

C:componentschartdirectorincludechartdir.h(1089) : error C2562: 'setResource' : 'void' function returning a value
        C:componentschartdirectorincludechartdir.h(1089) : see declaration of 'setResource'
C:componentschartdirectorincludechartdir.h(1090) : error C2562: 'setResource' : 'void' function returning a value
        C:componentschartdirectorincludechartdir.h(1090) : see declaration of 'setResource'

This is using Visual Studio 6, which is old, but which is used for legacy and compatibility reasons. When I recompile in Visual Studio 2010, I do not get an error.

  Re: V6.3 C++ Include File Error?
Posted by Peter Kwan on Dec-20-2018 20:08
Hi Electron,

Thanks for the information. Originally, we are thinking of an emergency fix. With this new information, I think we will modify the header file in the next version of ChartDirector to remove the "return" to ensure broader compatibility.

Regards
Peter Kwan