ancruna / mongoose

Automatically exported from code.google.com/p/mongoose
MIT License
0 stars 0 forks source link

compile error with g++ #324

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. compile mongoose.c with a C++ compiler

What is the expected output? What do you see instead?
successful compile, but I see a compile error

What version of the product are you using? On what operating system?
HEAD, linux

Please provide any additional information below.
A good C program is also a C++ program, this is not the case for mongoose, 
however.

g++ -DHAVE_STDINT -c mongoose.c -o lol.o
mongoose.c: In function 'int match_prefix(const char*, int, const char*)':
mongoose.c:782:62: error: invalid conversion from 'const void*' to 'const char*'

fix:

change the line from:
  if ((or_str = memchr(pattern, '|', pattern_len)) != NULL) {
to:
  if ((or_str = (char const*)memchr(pattern, '|', pattern_len)) != NULL) {

A simple function cast is needed to get around the C++ conversion rules from 
the void* pointer.

Also place this somewhere in mongoose.c please, say after #include "mongoose.h":

#ifdef __cplusplus
#if !defined(INT64_MAX)
# include <limits>
# define INT64_MAX std::numeric_limits<int64_t>::max()
#endif // INT64_MAX
#endif // __cplusplus

Rationale:
The C language does not offer all the features of C++, while some source-level 
compatibility exists between the languages. The cast does not burden the code 
at all and allows both C and C++ compilers to be used to compile the code.

Concretely, I need a custom type to get mongoose to work over UDP and for this 
I need C++ compatibility.

Original issue reported on code.google.com by janez...@gmail.com on 6 Mar 2012 at 2:28

GoogleCodeExporter commented 9 years ago
The INT64_MAX define in my fix is superfluous:

g++ -D__STDC_LIMIT_MACROS -c mongoose.c -o lol.o

compiles without problems, if the cast is present.

Original comment by janez...@gmail.com on 6 Mar 2012 at 2:46

GoogleCodeExporter commented 9 years ago
Submitted 
http://code.google.com/p/mongoose/source/detail?r=b6b4245ef6f3ac83806725b2ec73fc
37b3036b49, thanks 

Original comment by valenok on 6 Mar 2012 at 8:20