By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,330 Members | 1,572 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,330 IT Pros & Developers. It's quick & easy.

Conversion from 'void*' to pointer to non-'void' requires an explicit cast

P: n/a
Hi

I have this compilation problem when trying to convert C code to C++.

My function looks like this:

void FTPServer_ThreadLoop( void *arg_p )
{

FTPSettings_t* FTPSettings_p;

FTPSettings_p = arg_p;
...
...
...

}

typedef struct
{
FTPState_t State;
SOCKADDR_STORAGE sa;
SOCKADDRLEN salen;
SOCKET sock;
} FTPSettings_t;
When I compile I have this problem:

error C2440: '=' : cannot convert from 'void *' to 'FTPSettings_t *'
Conversion from 'void*' to pointer to non-'void' requires an
explicit cast
Please help me how to solve this problem. Thanks

Oct 4 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"Hakirato" <xa*******@gmail.comwrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
Hi

I have this compilation problem when trying to convert C code to C++.

My function looks like this:

void FTPServer_ThreadLoop( void *arg_p )
{

FTPSettings_t* FTPSettings_p;

FTPSettings_p = arg_p;
..
..
..

}

typedef struct
{
FTPState_t State;
SOCKADDR_STORAGE sa;
SOCKADDRLEN salen;
SOCKET sock;
} FTPSettings_t;
When I compile I have this problem:

error C2440: '=' : cannot convert from 'void *' to 'FTPSettings_t *'
Conversion from 'void*' to pointer to non-'void' requires an
explicit cast
Please help me how to solve this problem. Thanks
Do exactly what it says: add an explicit cast (and might as well make it a
one-liner while you're at it):

FTPSettings_t* FTPSettings_p = (FTPSettings_t*)arg_p;

or

FTPSettings_t* FTPSettings_p = static_cast<FTPSettings_t*>(arg_p);

-Howard
Oct 4 '06 #2

P: n/a
* Hakirato:
Hi

I have this compilation problem when trying to convert C code to C++.

My function looks like this:

void FTPServer_ThreadLoop( void *arg_p )
{

FTPSettings_t* FTPSettings_p;

FTPSettings_p = arg_p;
..
..
..

}

typedef struct
{
FTPState_t State;
SOCKADDR_STORAGE sa;
SOCKADDRLEN salen;
SOCKET sock;
} FTPSettings_t;
When I compile I have this problem:

error C2440: '=' : cannot convert from 'void *' to 'FTPSettings_t *'
Conversion from 'void*' to pointer to non-'void' requires an
explicit cast
Please help me how to solve this problem. Thanks
One purely technical answer is:

void FTPServer_ThreadLoop_C( void* pSettings )
{
FTPServer_ThreadLoop( *static_cast<FTPSettings*>( pSettings ) );
}

which calls the following more type safe function:

void FTPServer_ThreadLoop( FTPSettings& settings )
{
...
}

Given that, for maintainability it can be a good idea to do something like

struct FTPState
{
FTPState_t State;
SOCKADDR_STORAGE sa;
SOCKADDRLEN salen;
SOCKET sock;

void ThreadLoop()
{
...
}
};

namespace g
{
FTPState* pFtpState; // Managed by code not shown here.
}

void FTPServer_ThreadLoop( FTPSettings& settings )
{
g::pFtpState->ThreadLoop();
}

and then notice that there's probably initialization (which should be a
constructor), destruction (which should be a destructor), and matters of
access to be granted or restricted, and so on.

Actually I wouldn't use the namespace as shown above, and in fact the
code wouldn't resemble this at all. <g I'm trying to write something
you'd find at least slightly familiar. Hope this helps.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Oct 4 '06 #3

P: n/a
Hi

Thanks for helping me this out..

//Hakirato

Alf P. Steinbach skrev:
* Hakirato:
Hi

I have this compilation problem when trying to convert C code to C++.

My function looks like this:

void FTPServer_ThreadLoop( void *arg_p )
{

FTPSettings_t* FTPSettings_p;

FTPSettings_p = arg_p;
..
..
..

}

typedef struct
{
FTPState_t State;
SOCKADDR_STORAGE sa;
SOCKADDRLEN salen;
SOCKET sock;
} FTPSettings_t;
When I compile I have this problem:

error C2440: '=' : cannot convert from 'void *' to 'FTPSettings_t *'
Conversion from 'void*' to pointer to non-'void' requires an
explicit cast
Please help me how to solve this problem. Thanks

One purely technical answer is:

void FTPServer_ThreadLoop_C( void* pSettings )
{
FTPServer_ThreadLoop( *static_cast<FTPSettings*>( pSettings ) );
}

which calls the following more type safe function:

void FTPServer_ThreadLoop( FTPSettings& settings )
{
...
}

Given that, for maintainability it can be a good idea to do something like

struct FTPState
{
FTPState_t State;
SOCKADDR_STORAGE sa;
SOCKADDRLEN salen;
SOCKET sock;

void ThreadLoop()
{
...
}
};

namespace g
{
FTPState* pFtpState; // Managed by code not shown here.
}

void FTPServer_ThreadLoop( FTPSettings& settings )
{
g::pFtpState->ThreadLoop();
}

and then notice that there's probably initialization (which should be a
constructor), destruction (which should be a destructor), and matters of
access to be granted or restricted, and so on.

Actually I wouldn't use the namespace as shown above, and in fact the
code wouldn't resemble this at all. <g I'm trying to write something
you'd find at least slightly familiar. Hope this helps.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Oct 5 '06 #4

P: n/a
* Hakirato:
Hi

Thanks for helping me this out..
Well, one shouldn't post Usenet articles in the middle of the night. At
least, I shouldn't.

The last function should be

void FTPServer_ThreadLoop( FTPSettings& settings )
{
settings.ThreadLoop();
}

rather than what I wrote.

Btw., when reading this posting, do you notice any problem with the
order the text appears in?

>
//Hakirato

Alf P. Steinbach skrev:
>* Hakirato:
>>Hi

I have this compilation problem when trying to convert C code to C++.

My function looks like this:

void FTPServer_ThreadLoop( void *arg_p )
{

FTPSettings_t* FTPSettings_p;

FTPSettings_p = arg_p;
..
..
..

}

typedef struct
{
FTPState_t State;
SOCKADDR_STORAGE sa;
SOCKADDRLEN salen;
SOCKET sock;
} FTPSettings_t;
When I compile I have this problem:

error C2440: '=' : cannot convert from 'void *' to 'FTPSettings_t *'
Conversion from 'void*' to pointer to non-'void' requires an
explicit cast
Please help me how to solve this problem. Thanks
One purely technical answer is:

void FTPServer_ThreadLoop_C( void* pSettings )
{
FTPServer_ThreadLoop( *static_cast<FTPSettings*>( pSettings ) );
}

which calls the following more type safe function:

void FTPServer_ThreadLoop( FTPSettings& settings )
{
...
}

Given that, for maintainability it can be a good idea to do something like

struct FTPState
{
FTPState_t State;
SOCKADDR_STORAGE sa;
SOCKADDRLEN salen;
SOCKET sock;

void ThreadLoop()
{
...
}
};

namespace g
{
FTPState* pFtpState; // Managed by code not shown here.
}

void FTPServer_ThreadLoop( FTPSettings& settings )
{
g::pFtpState->ThreadLoop();
}

and then notice that there's probably initialization (which should be a
constructor), destruction (which should be a destructor), and matters of
access to be granted or restricted, and so on.

Actually I wouldn't use the namespace as shown above, and in fact the
code wouldn't resemble this at all. <g I'm trying to write something
you'd find at least slightly familiar. Hope this helps.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Oct 5 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.