For Programmers: Free Programming Magazines  


Home > Archive > VC Language > January 2006 > '_beginthread' help - undeclared identifier error









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author '_beginthread' help - undeclared identifier error
ern

2006-01-18, 7:08 pm

I can't figure out why I'm getting an 'undeclared identifier error' and
a 'redeclaration' error when I try to use _beginthread. I used it the
same exact way in another case...

....
char * arg1;
arg1 = command( );
_beginthread(executeScript,NULL,&arg1);
....

int executeScript(char* pathName){

....

}

I couldn't figure it out by looking at docs. Tried making
executeScript return void, but couldn't get it to compile.

Igor Tandetnik

2006-01-18, 7:08 pm

ern <erniedude@gmail.com> wrote:
> I can't figure out why I'm getting an 'undeclared identifier error'
> and a 'redeclaration' error when I try to use _beginthread. I used
> it the same exact way in another case...
>
> ...
> char * arg1;
> arg1 = command( );
> _beginthread(executeScript,NULL,&arg1);
> ...
>
> int executeScript(char* pathName){


Quote the exact error message, and show which line it points to.

Have you included process.h ?

The prototype of the thread function _beginthread expects is as follows:

void __cdecl executeScript(void *);

You should exactly follow this prototype.

Note also that _beginthread is not recommened for a number of reasons -
use _beginthreadex instead. The expected prototype for _beginthreadex is

unsigned __stdcall executeScript(void *);

Also note that you should close the handle returned by _beginthreadex
with CloseHandle.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


ern

2006-01-18, 7:08 pm


Igor Tandetnik wrote:
> Quote the exact error message, and show which line it points to.


First error message points to this line:

_beginthread(executeScript,NULL,&arg1);

Error message says:

"undeclared identifier"

Second error message points to this line:

void __cdecl executeScript(void* path){

Error message says:

"redefinition; different type modifiers"

> Have you included process.h ?


Yes

> The prototype of the thread function _beginthread expects is as follows:
>
> void __cdecl executeScript(void *);
>
> You should exactly follow this prototype.


OK. I changed it, but the error messages remain the same.

> Note also that _beginthread is not recommened for a number of reasons -
> use _beginthreadex instead.


Why is 'ex' better ? I've been using _beginthread in my app. with no
problems.

> The expected prototype for _beginthreadex is
> unsigned __stdcall executeScript(void *);
>
> Also note that you should close the handle returned by _beginthreadex
> with CloseHandle.


Thanks sooooo much for your help !

JD

2006-01-18, 7:08 pm


"ern" <erniedude@gmail.com> wrote in message
news:1137601032.255504.223140@f14g2000cwb.googlegroups.com...
>
> Igor Tandetnik wrote:
>
> First error message points to this line:
>
> _beginthread(executeScript,NULL,&arg1);
>
> Error message says:
>
> "undeclared identifier"
>
> Second error message points to this line:
>
> void __cdecl executeScript(void* path){
>
> Error message says:
>
> "redefinition; different type modifiers"
>
>
> Yes
>
>
> OK. I changed it, but the error messages remain the same.
>
>
> Why is 'ex' better ? I've been using _beginthread in my app. with no
> problems.
>
>
> Thanks sooooo much for your help !
>


Are you compiling with a multi-threaded version of the run time library?

Mike P


Igor Tandetnik

2006-01-18, 7:08 pm

ern <erniedude@gmail.com> wrote:
> Igor Tandetnik wrote:
> First error message points to this line:
>
> _beginthread(executeScript,NULL,&arg1);
>
> Error message says:
>
> "undeclared identifier"


Are you linking to multithreaded CRT? Go to Project | Properties | C/C++
| Code Generation | Runtime Library, make sure it is not set to
Single-threaded nor Single-threaded Debug.

> Second error message points to this line:
>
> void __cdecl executeScript(void* path){
>
> Error message says:
>
> "redefinition; different type modifiers"


You are declaring executeScript somewhere else, and the two declarations
don't match. Make sure they do.

>
> Why is 'ex' better ? I've been using _beginthread in my app. with no
> problems.


The main problem is that _beginthread automatically closes the thread
handle when the thread terminates. So you cannot reliably use this
handle to wait on the thread. It also does not allow the thread function
to provide an exit code for the thread, but this is rarely a concern.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


ern

2006-01-18, 7:08 pm


JD wrote:

> Are you compiling with a multi-threaded version of the run time library?
>
> Mike P


I don't know.

I'm using _beginthread( ) in another part of my application in the same
exact way, and it works great.

ern

2006-01-18, 7:08 pm

Yes. I am compiling with a multi-threaded version of the run time
library. It is set to "Debug Multithreaded DLL."

ern

2006-01-18, 7:08 pm


Igor Tandetnik wrote:
> Are you linking to multithreaded CRT? Go to Project | Properties | C/C++
> | Code Generation | Runtime Library, make sure it is not set to
> Single-threaded nor Single-threaded Debug.


It says "Debug Multithreaded DLL."

> You are declaring executeScript somewhere else, and the two declarations
> don't match. Make sure they do.


Nope, the phrase "executeScript" only appears twice in my program:

1. the _beginthread call
2. function definition

Igor Tandetnik

2006-01-18, 7:08 pm

ern <erniedude@gmail.com> wrote:
> Igor Tandetnik wrote:
>
> First error message points to this line:
>
> _beginthread(executeScript,NULL,&arg1);
>
> Error message says:
>
> "undeclared identifier"


Which one? _beginthread, executeScript or arg1?

>
> Yes


Double-check. If the compiler says that _beginthread is undeclared
identifier, than you have not.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


Igor Tandetnik

2006-01-18, 7:08 pm

ern <erniedude@gmail.com> wrote:
> Igor Tandetnik wrote:
>
> It says "Debug Multithreaded DLL."
>
>
> Nope, the phrase "executeScript" only appears twice in my program:
>
> 1. the _beginthread call
> 2. function definition


Does the function definition or declaration appear above _beginthread
call? If not, this is the source of your "undeclared identifier" error.
It would be much easier to diagnose had you quoted the exact compiler
error, in full. Why do you resist doing it?
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


ern

2006-01-18, 7:08 pm


Igor Tandetnik wrote:
> ern <erniedude@gmail.com> wrote:
>
> Which one? _beginthread, executeScript or arg1?


executeScript

>
> Double-check. If the compiler says that _beginthread is undeclared
> identifier, than you have not.


I'm positive I've included process.h . I checked it and my other
_beginthread usage wouldn't be working without it. The undeclared
identifier is executeScript, not _beginthread.

Thanks,

ern

2006-01-18, 7:08 pm


Igor Tandetnik wrote:
> Does the function definition or declaration appear above _beginthread
> call? If not, this is the source of your "undeclared identifier" error.
> It would be much easier to diagnose had you quoted the exact compiler
> error, in full. Why do you resist doing it?


I aplogize. I thought I DID quote the exact compiler error in full.
The only thing I didn't include was the error code numbers. For #1 and
#2 already mentioned...

1. myApplication.c(762) : error C2065: 'executeScript' : undeclared
identifier
2. myApplication.c(771) : error C2373: 'executeScript' : redefinition;
different type modifiers

BTW, placing the declaration before the call fixed the problem. I knew
it had to be something simple. Thanks a bunch for helping !

Alexander Grigoriev

2006-01-19, 4:11 am

Declare your executeScript _before_ you use it in _beginthread call.

Your error message is related to executeScript, NOT to _beginthread.

"ern" <erniedude@gmail.com> wrote in message
news:1137602183.561057.192240@g14g2000cwa.googlegroups.com...
>
> Igor Tandetnik wrote:
>
> It says "Debug Multithreaded DLL."
>
>
> Nope, the phrase "executeScript" only appears twice in my program:
>
> 1. the _beginthread call
> 2. function definition
>



Tim Roberts

2006-01-20, 3:59 am

"ern" <erniedude@gmail.com> wrote:
>
>I aplogize. I thought I DID quote the exact compiler error in full.
>The only thing I didn't include was the error code numbers.


That's not AT ALL true! Your original message was, and I quote:

>I can't figure out why I'm getting an 'undeclared identifier error' and
>a 'redeclaration' error when I try to use _beginthread.


The natural assumption from this message -- an assumption made by myself
and by all of the other responders -- was that the error message referred
to _beginthread being undeclared. Had you actually included the full error
message from the beginning, you could have had your answer on the first
reply, instead of the 10th reply.

>1. myApplication.c(762) : error C2065: 'executeScript' : undeclared
>identifier
>2. myApplication.c(771) : error C2373: 'executeScript' : redefinition;
>different type modifiers
>
>BTW, placing the declaration before the call fixed the problem. I knew
>it had to be something simple. Thanks a bunch for helping !


Yes, but do you understand WHY this happened?
--
- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
ern

2006-01-27, 7:05 pm


Tim Roberts wrote:
> "ern" <erniedude@gmail.com> wrote:
>
> That's not AT ALL true! Your original message was, and I quote:
>
>
> The natural assumption from this message -- an assumption made by myself
> and by all of the other responders -- was that the error message referred
> to _beginthread being undeclared. Had you actually included the full error
> message from the beginning, you could have had your answer on the first
> reply, instead of the 10th reply.


I was talking about my second post (message #3). That's the one I
thought I did quote the error in full. I'm new to this newsgroup and I
aplogize for any inconvenience. I really appreciate all of the help
the others provided. It's true that it took many replies to solve the
problem, but there was also useful info regarding _beginthread that was
articulated in this discussion.

>
> Yes, but do you understand WHY this happened?


Yes, I do. Igor was helpful in explaining that in a previous message.
Instead of picking on newcomers to this group (which is non-topical and
unnecessary), why don't YOU explain why this happened since you feel it
is so important I know. This would be much more helpful than
[redunantly] attacking a thread-posting approach.

Tim Roberts

2006-01-29, 9:57 pm

"ern" <erniedude@gmail.com> wrote:
>
>Tim Roberts wrote:
>
>
>Yes, I do. Igor was helpful in explaining that in a previous message.
>Instead of picking on newcomers to this group (which is non-topical and
>unnecessary),


I was not "picking" on you at all. There are certain techniques for asking
newsgroup questions, such that you get a correct and useful answer in the
shortest amount of time with a minimum of follow-up questions. My response
here was just trying to point out the "flaw", if you will, in your original
post which caused the thread to go on for so long. My hope was that you
would file that away for next time.

It's quite possible that you had already figured that out, of course, but
it wasn't clear to me from your last response.

>why don't YOU explain why this happened since you feel it
>is so important I know.


It IS important, darn it. If someone tells you how to modify your program
so that it compiles, but you don't understand WHY that modification solves
the problem, then you won't know how to solve a similar problem next time.
It's the old "give a man a fish / teach him how to fish" scenario.

Here's the root cause of the problem. Your _beginthread call included a
reference to executeScript. executeScript had not been defined, so the
compiler issued an error, and then "invented" a definition for it so that
it doesn't generate hundreds of errors. Later, when you declared your own
executeScript, your definition didn't match the one the compiler invented,
so you get another error.

>This would be much more helpful than [redunantly] attacking a
>thread-posting approach.


I didn't "attack" you in any way. I didn't call you names, nor did I
belittle you.
--
- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com