Hi!

I added to my project in Visual Studio 2008 library to work with Neural Networks (FANN) http://www.geocities.com/freegoldbar/fann_cpp.zip.

When i try to compile, following error occurs:

c:\neu\neur\neur\src\include\fann_cpp.h(921) : error C2440: 'reinterpret_cast' : cannot convert from 'va_list' to 'const unsigned int *'
Conversion requires a constructor or user-defined-conversion operator, which can't be used by const_cast or reinterpret_cast
c:\neu\neur\neur\src\include\fann_cpp.h(971) : error C2440: 'reinterpret_cast' : cannot convert from 'va_list' to 'const unsigned int *'
Conversion requires a constructor or user-defined-conversion operator, which can't be used by const_cast or reinterpret_cast
c:\neu\neur\neur\src\include\fann_cpp.h(1018) : error C2440: 'reinterpret_cast' : cannot convert from 'va_list' to 'const unsigned int *'
Conversion requires a constructor or user-defined-conversion operator, which can't be used by const_cast or reinterpret_cast
c:\neu\neur\neur\src\include\fann_cpp.h(2484) : warning C4244: 'initializing' : conversion from 'float' to 'fann_type', possible loss of data
c:\neu\neur\neur\src\include\fann_cpp.h(3443) : error C3641: 'FANN::neural_net::internal_callback' : invalid calling convention '__stdcall ' for function compiled with /clr:pure or /clr:safe

Dani AI

Generated

As suggested, the root cause is two-fold: the C++ wrapper is treating a va_list like a pointer to an array (which you cannot do), and some callbacks in the header use a native calling convention that conflicts with a /clr:pure or /clr:safe build. The va_list object must be walked with va_start/va_arg/va_end and its values copied into a real array (or std::vector) before passing a pointer to an API that expects const unsigned int *. See the language reference for va_list/va_arg. (en.cppreference.com)

A safe replacement for the reinterpret_cast approach is to build a small array and call the C API that accepts an array. Example (conceptual — adapt to the wrapper locations in fann_cpp.h):

#include <cstdarg>
#include <vector>
#include <fann.h> // C API

struct fann *create_from_varargs(unsigned int num_layers, ...)
{
    va_list ap;
    va_start(ap, num_layers);
    std::vector<unsigned int> layers;
    layers.reserve(num_layers);
    for (unsigned int i = 0; i < num_layers; ++i) {
        layers.push_back(va_arg(ap, unsigned int));
    }
    va_end(ap);

    return fann_create_standard_array(num_layers, layers.data());
}

For the C3641 "stdcall" error: that message means the file is being compiled with /clr:pure or /clr:safe and those modes only permit the `clrcallcalling convention for managed functions. The practical fixes are (a) compile the FANN C++ wrapper translation unit as native (disable CLR for that file), (b) wrap the native header includes in#pragma managed(push, off)/#pragma managed(pop)`, or (c) put the wrapper into a native static/dynamic library and link it from the managed project. You can change the per-file CLR setting from Solution Explorer → right‑click the .cpp → Properties → C/C++ → General → "Compile with Common Language Runtime support". (learn.microsoft.com)

Finally, the C4244 float->fann_type warning is harmless if fann_type is float; fann_type can be float, double or int depending on which header you include (floatfann.h, doublefann.h, fixedfann.h). Either include the matching header or make the conversion explicit with static_cast<fann_type>(value). If the geocities wrapper is old, consider using the current libfann sources (official repo and docs) instead of the archived zip. (libfann.github.io)

Summary checklist

  • Replace the reinterpret_cast lines in fann_cpp.h with a va_arg loop into an array/vector (then pass .data()). (en.cppreference.com)
  • Build the wrapper as native or isolate it from /clr to avoid C3641. (learn.microsoft.com)
  • Resolve the float->fann_type warning by including the correct FANN header or using an explicit cast. (libfann.github.io)

This addresses the concrete compiler errors you posted and gives a minimal, safe patch path that keeps the underlying C API usage correct.

Recommended Answers

All 2 Replies

its not possible to typecast a va_list object into an int* pointer. What you will have to do is create an int array, loop through the va_list and then pass the array to the function. google for va_list to get examples of looping through the list.

Thank you, i will try to do so.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.