Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Can't compile this with Cygwin!

Reply
Thread Tools

Can't compile this with Cygwin!

 
 
JS
Guest
Posts: n/a
 
      03-18-2005
I use winXP and have installed Cygwin. I use Dev-C++ and the Cygwin
compiler, but for some reason I can't compile this code:

#include <setjmp.h>
#include <stdio.h>
#include <stdlib.h>


typedef int othread_t;

typedef struct _othread_attr_t {
} othread_attr_t;

#define STACK_SIZE 1024


struct pcb {
void *(*start_routine) (void *);
void *arg;
jmp_buf state;
int stak[STACK_SIZE];
};

static struct pcb first_thread;

struct pcb *current = &first_thread;
struct pcb *ready = NULL;

int othread_create (othread_t *threadp,
const othread_attr_t *attr,
void *(*start_routine) (void *),
void *arg)
{
int *state_pointer;
int lokalt_reserveret;

struct pcb *pcb_pointer;

pcb_pointer = (struct pcb *) malloc(sizeof(struct pcb));
if(pcb_pointer == NULL) {

exit(-1);
}

pcb_pointer->start_routine = start_routine;
pcb_pointer->arg = arg;

if(setjmp(pcb_pointer->state)) {



current->start_routine(current->arg);

printf("En tråd har returneret - alt stoppes\n");
exit(0);
}

state_pointer = (int *) &pcb_pointer->state;
lokalt_reserveret = state_pointer[JB_BP] - state_pointer[JB_SP];
state_pointer[JB_BP] = (int) (pcb_pointer->stak + STACK_SIZE);
state_pointer[JB_SP] = (int) state_pointer[JB_BP] - lokalt_reserveret;


ready = pcb_pointer;


*threadp = (int) pcb_pointer;

return 0;
}


int othread_yield (void)
{
if(ready != NULL) {

struct pcb *old = current;
current = ready;
ready = old;
if(setjmp(old->state) == 0) {
longjmp(current->state, 1);
}
}

return 0;
}



void *other(void *arg)
{
printf("Hello world from other\n");

othread_yield();

printf("other still going strong\n");

othread_yield();

printf("Godbye world from other\n");

return NULL;
}


int main(void)
{
othread_t t1;

othread_create(&t1, NULL, other, NULL);

printf("Hello world from main\n");

othread_yield();

printf("main still going strong\n");

othread_yield();

printf("Godbye world from main\n");

othread_yield();


printf("Is never reached\n");

return 0;
}



The error I get is:

56 H:\thread\thread.c `JB_BP' undeclared (first use in this function)
(Each undeclared identifier is reported only once
for each function it appears in.)

56 H:\thread\thread.c `JB_SP' undeclared (first use in this function)
make H:\thread\make *** [thread.o] Error 1

when I compile the same code on Linux it works fine! But I am sure that I
use Cygwin so that should be as good as using Linux.

Hope someone can help



 
Reply With Quote
 
 
 
 
Jens.Toerring@physik.fu-berlin.de
Guest
Posts: n/a
 
      03-19-2005
JS <(E-Mail Removed)> wrote:

<lots of cde snipped>

> The error I get is:


> 56 H:\thread\thread.c `JB_BP' undeclared (first use in this function)
> (Each undeclared identifier is reported only once
> for each function it appears in.)


> 56 H:\thread\thread.c `JB_SP' undeclared (first use in this function)
> make H:\thread\make *** [thread.o] Error 1


> when I compile the same code on Linux it works fine! But I am sure that I
> use Cygwin so that should be as good as using Linux.


No, it doesn't compile, not even on Linux. I just took your code
and tried to compile it (under Linux) and, voila,

thr.c:55: error: `JB_BP' undeclared (first use in this function)
thr.c:55: error: (Each undeclared identifier is reported only once
thr.c:55: error: for each function it appears in.)
thr.c:55: error: `JB_SP' undeclared (first use in this function)
thr.c:27: warning: unused parameter `attr'
thr.c: In function `other':
thr.c:86: warning: unused parameter `arg'

basically the same error message. So you must be defining 'JS_BP'
and 'JB_BP' in places you don't show. It's nowhere defined in the
code you posted (and I have no idea what they should be), so the
compiler is completely right in complaining. (BTW, there's no good
reason to cast the return value of malloc(), identifiers starting
with an underscore are reserved for the implementation, your type-
def of 'othread_attr_t' looks mysterious (a structure with no
members), your casts look very strange to say the least (int's and
pointers may have different sizes), and lots more of things that
make no sense at all). What that's all supposed to do?

Regards, Jens
--
\ Jens Thoms Toerring ___ http://www.velocityreviews.com/forums/(E-Mail Removed)-berlin.de
\__________________________ http://www.toerring.de
 
Reply With Quote
 
 
 
 
Walter Roberson
Guest
Posts: n/a
 
      03-19-2005
In article <(E-Mail Removed)>,
<(E-Mail Removed)-berlin.de> wrote:
:basically the same error message. So you must be defining 'JS_BP'
:and 'JB_BP' in places you don't show. It's nowhere defined in the
:code you posted (and I have no idea what they should be),

They appear to be in <setjmp.h> at least on some systems.

My copy of the standard is packed at the moment, so I can't check
to see whether the standard has anything to say about what the
interior structure of a jump buffer is.
--
Feep if you love VT-52's.
 
Reply With Quote
 
JS
Guest
Posts: n/a
 
      03-19-2005
On Sat, 19 Mar 2005 00:18:40 +0000, Jens.Toerring wrote:

> JS <(E-Mail Removed)> wrote:
>
> <lots of cde snipped>
>
>> The error I get is:

>
>> 56 H:\thread\thread.c `JB_BP' undeclared (first use in this function)
>> (Each undeclared identifier is reported only once
>> for each function it appears in.)

>
>> 56 H:\thread\thread.c `JB_SP' undeclared (first use in this function)
>> make H:\thread\make *** [thread.o] Error 1

>
>> when I compile the same code on Linux it works fine! But I am sure that I
>> use Cygwin so that should be as good as using Linux.

>
> No, it doesn't compile, not even on Linux. I just took your code
> and tried to compile it (under Linux) and, voila,
>
> thr.c:55: error: `JB_BP' undeclared (first use in this function)
> thr.c:55: error: (Each undeclared identifier is reported only once
> thr.c:55: error: for each function it appears in.)
> thr.c:55: error: `JB_SP' undeclared (first use in this function)
> thr.c:27: warning: unused parameter `attr'
> thr.c: In function `other':
> thr.c:86: warning: unused parameter `arg'
>
> basically the same error message. So you must be defining 'JS_BP'
> and 'JB_BP' in places you don't show. It's nowhere defined in the
> code you posted (and I have no idea what they should be), so the
> compiler is completely right in complaining. (BTW, there's no good
> reason to cast the return value of malloc(), identifiers starting
> with an underscore are reserved for the implementation, your type-
> def of 'othread_attr_t' looks mysterious (a structure with no
> members), your casts look very strange to say the least (int's and
> pointers may have different sizes), and lots more of things that
> make no sense at all). What that's all supposed to do?
>
> Regards, Jens



Well it compiles fine on my Ubuntu Linux....

 
Reply With Quote
 
Jens.Toerring@physik.fu-berlin.de
Guest
Posts: n/a
 
      03-19-2005
JS <(E-Mail Removed)> wrote:
> On Sat, 19 Mar 2005 00:18:40 +0000, Jens.Toerring wrote:


>> JS <(E-Mail Removed)> wrote:
>>
>> <lots of cde snipped>
>>
>>> The error I get is:

>>
>>> 56 H:\thread\thread.c `JB_BP' undeclared (first use in this function)
>>> (Each undeclared identifier is reported only once
>>> for each function it appears in.)

>>
>>> 56 H:\thread\thread.c `JB_SP' undeclared (first use in this function)
>>> make H:\thread\make *** [thread.o] Error 1

>>
>>> when I compile the same code on Linux it works fine! But I am sure that I
>>> use Cygwin so that should be as good as using Linux.

>>
>> No, it doesn't compile, not even on Linux. I just took your code
>> and tried to compile it (under Linux) and, voila,
>>
>> thr.c:55: error: `JB_BP' undeclared (first use in this function)
>> thr.c:55: error: (Each undeclared identifier is reported only once
>> thr.c:55: error: for each function it appears in.)
>> thr.c:55: error: `JB_SP' undeclared (first use in this function)
>> thr.c:27: warning: unused parameter `attr'
>> thr.c: In function `other':
>> thr.c:86: warning: unused parameter `arg'
>>
>> basically the same error message. So you must be defining 'JS_BP'
>> and 'JB_BP' in places you don't show. It's nowhere defined in the


> Well it compiles fine on my Ubuntu Linux....


But not in standard compliant mode - unless you ask for that you get
lots of non-portable extensions included - and you can't expect them
to exist on a completely different type of system. If you search the
C89 or C99 standard you won't find the string "JB" anywhere. If you
want to check compile with at least the options '-ansi -pedantic' -
normally gcc is far from standard compliant (and even in the POSIX
standard I didn't find anything about 'JB_[A-Z]P' when looking up
setjmp() and things related to it). And while 'JB_SP' and 'JB_BP'
seem to be defined somewhere in the innards for setjmp() on IA32
Linux I only found 'JB_SP' in a header file for IRIX or OSF1, but not
'JB_BP'. There are no guarantees at all, at least from the C standard,
when you start to mess around with the innards of a 'jmp_buf' variable
- what's stored there and where and in what format is as system-depen-
dent as you can get.
Regards, Jens
--
\ Jens Thoms Toerring ___ (E-Mail Removed)-berlin.de
\__________________________ http://www.toerring.de
 
Reply With Quote
 
JS
Guest
Posts: n/a
 
      03-19-2005
> > Well it compiles fine on my Ubuntu Linux....
>
> But not in standard compliant mode - unless you ask for that you get
> lots of non-portable extensions included - and you can't expect them
> to exist on a completely different type of system. If you search the
> C89 or C99 standard you won't find the string "JB" anywhere. If you
> want to check compile with at least the options '-ansi -pedantic' -
> normally gcc is far from standard compliant (and even in the POSIX
> standard I didn't find anything about 'JB_[A-Z]P' when looking up
> setjmp() and things related to it). And while 'JB_SP' and 'JB_BP'
> seem to be defined somewhere in the innards for setjmp() on IA32
> Linux I only found 'JB_SP' in a header file for IRIX or OSF1, but not
> 'JB_BP'. There are no guarantees at all, at least from the C standard,
> when you start to mess around with the innards of a 'jmp_buf' variable
> - what's stored there and where and in what format is as system-depen-
> dent as you can get.



But how can it be that you get the error messages and I don't get them in
Ubuntu Linux, is it because I don't compile with the right commands? I am a
bit concerned that my compiler don't detect the errors, when your compiler
does...


 
Reply With Quote
 
Flash Gordon
Guest
Posts: n/a
 
      03-19-2005
JS wrote:
>>>Well it compiles fine on my Ubuntu Linux....

>>
>>But not in standard compliant mode - unless you ask for that you get
>>lots of non-portable extensions included - and you can't expect them
>>to exist on a completely different type of system. If you search the
>>C89 or C99 standard you won't find the string "JB" anywhere. If you
>>want to check compile with at least the options '-ansi -pedantic' -

^^^^^^^^^^^^^^^
>>normally gcc is far from standard compliant (and even in the POSIX


<snip>

> But how can it be that you get the error messages and I don't get them in
> Ubuntu Linux, is it because I don't compile with the right commands? I am a
> bit concerned that my compiler don't detect the errors, when your compiler
> does...


As stated above in the text you quoted, use the '-ansi -pedantic'
options on gcc.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      03-19-2005
Flash Gordon wrote:
> JS wrote:
>
> <snip>
>
>> But how can it be that you get the error messages and I don't get
>> them in Ubuntu Linux, is it because I don't compile with the right
>> commands? I am a bit concerned that my compiler don't detect the
>> errors, when your compiler does...

>
> As stated above in the text you quoted, use the '-ansi -pedantic'
> options on gcc.


Also include -W -Wall.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson


 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      03-19-2005
CBFalconer <(E-Mail Removed)> writes:
> Flash Gordon wrote:
>> JS wrote:
>>
>> <snip>
>>
>>> But how can it be that you get the error messages and I don't get
>>> them in Ubuntu Linux, is it because I don't compile with the right
>>> commands? I am a bit concerned that my compiler don't detect the
>>> errors, when your compiler does...

>>
>> As stated above in the text you quoted, use the '-ansi -pedantic'
>> options on gcc.

>
> Also include -W -Wall.


There's been some debate about whether "-W -Wall" is as useful as it
should be (some of the warnings may be questionable), but at worst
you'll get too many warnings, which is probably better than too few.
You just have to know which ones to ignore.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
Richard Bos
Guest
Posts: n/a
 
      03-21-2005
http://www.velocityreviews.com/forums/(E-Mail Removed)-cnrc.gc.ca (Walter Roberson) wrote:

> In article <(E-Mail Removed)>,
> <(E-Mail Removed)-berlin.de> wrote:
> :basically the same error message. So you must be defining 'JS_BP'
> :and 'JB_BP' in places you don't show. It's nowhere defined in the
> :code you posted (and I have no idea what they should be),
>
> They appear to be in <setjmp.h> at least on some systems.


Then some systems are broken; those identifiers are the programmer's,
not the implementation's.

Richard
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
compile directive for conditional compile for Java 1.4 versus Java 5 timjowers Java 7 02-02-2011 12:08 AM
How to compile the following source code in VC6// I have error inVC++6 but compile ok in GCC fAnSKyer C++ 2 06-07-2009 07:57 AM
computation at compile time i.e. compile time functions usingtemplates Carter C++ 2 03-04-2009 06:43 PM
Compile versus not compile (VS 2005)?? stupid48@gmail.com ASP .Net 1 04-11-2008 08:24 PM
cant compile on linux system.cant compile on cant compile onlinux system. Nagaraj C++ 1 03-01-2007 11:18 AM



Advertisments