Unix Programming - compilation problem

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > September 2006 > compilation problem





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 compilation problem
shaanxxx

2006-09-27, 7:30 am

#include<stdio.h>
#include<pthread.h>
int main()
{
return 0;
}

void callCancelHandlerSubscribe (void *param)
{
printf("++++callCancelHandlerSubscribe+++\n");
}

void myfunc ()
{
pthread_cleanup_push(callCancelHandlerSu
bscribe, 0);
return ;
}


Am I doing any thing wrong here ? i am not able to compile the above
code .

Here are error and compiler information :

SHQ >> cc test.c -lpthread
"test.c", line 21: syntax error before or at: <EOF>
cc: acomp failed for test.c
SHQ >> CC test.c -lpthread
"test.c", line 21: Error: "}" expected instead of EOF.
1 Error(s) detected.
SHQ >> cc -V
cc: Sun WorkShop 6 update 2 C 5.3 2001/05/15
usage: cc [ options] files. Use 'cc -flags' for details
SHQ >> CC -V
CC: Sun WorkShop 6 update 2 C++ 5.3 Patch 111685-19 2003/12/18

raxitsheth2000@yahoo.co.in

2006-09-27, 7:30 am

i do think on Solaris OS (if ur using) you also required matching
cleanup_pop
chkout man page of pthread_cleanup_push

--raxit sheth
shaanxxx wrote:
> #include<stdio.h>
> #include<pthread.h>
> int main()
> {
> return 0;
> }
>
> void callCancelHandlerSubscribe (void *param)
> {
> printf("++++callCancelHandlerSubscribe+++\n");
> }
>
> void myfunc ()
> {
> pthread_cleanup_push(callCancelHandlerSu
bscribe, 0);
> return ;
> }
>
>
> Am I doing any thing wrong here ? i am not able to compile the above
> code .
>
> Here are error and compiler information :
>
> SHQ >> cc test.c -lpthread
> "test.c", line 21: syntax error before or at: <EOF>
> cc: acomp failed for test.c
> SHQ >> CC test.c -lpthread
> "test.c", line 21: Error: "}" expected instead of EOF.
> 1 Error(s) detected.
> SHQ >> cc -V
> cc: Sun WorkShop 6 update 2 C 5.3 2001/05/15
> usage: cc [ options] files. Use 'cc -flags' for details
> SHQ >> CC -V
> CC: Sun WorkShop 6 update 2 C++ 5.3 Patch 111685-19 2003/12/18


raxitsheth2000@yahoo.co.in

2006-09-27, 7:30 am

copying part of man from my linux distro.

Matching pairs of pthread_cleanup_push and pthread_cleanup_pop must
occur in the same function, at the same level of block nesting.
Actu-
ally, pthread_cleanup_push and pthread_cleanup_pop are macros,
and the
expansion of pthread_cleanup_push introduces an open brace {
with the
matching closing brace } being introduced by the expansion
of the
matching pthread_cleanup_pop.


To remove compilation error just write *****THIS IS NOT
RECOMMENDED*******
void myfunc ()
{
pthread_cleanup_push(callCancelHandlerSu
bscribe, 0);
return ;
}

}<---note this extra curly bracket.

shaanxxx

2006-09-27, 7:30 am


raxitsheth2000@yahoo.co.in wrote:[vbcol=seagreen]
> i do think on Solaris OS (if ur using) you also required matching
> cleanup_pop
> chkout man page of pthread_cleanup_push
>
> --raxit sheth
> shaanxxx wrote:


Thanks

Nils O. Selåsdal

2006-09-27, 7:30 am

raxitsheth2000@yahoo.co.in wrote:
> copying part of man from my linux distro.
>
> Matching pairs of pthread_cleanup_push and pthread_cleanup_pop must
> occur in the same function, at the same level of block nesting.
> Actu-
> ally, pthread_cleanup_push and pthread_cleanup_pop are macros,
> and the
> expansion of pthread_cleanup_push introduces an open brace {
> with the
> matching closing brace } being introduced by the expansion
> of the
> matching pthread_cleanup_pop.
>
>
> To remove compilation error just write *****THIS IS NOT
> RECOMMENDED*******
> void myfunc ()
> {
> pthread_cleanup_push(callCancelHandlerSu
bscribe, 0);
> return ;
> }
>
> }<---note this extra curly bracket.

Right. It is much better to just to what the docs says.
That extra curly brace makes the code a syntax error on
other systems, and can be a runtime error on others.
shaanxxx

2006-09-27, 1:21 pm


Nils O. Sel=E5sdal wrote:
> raxitsheth2000@yahoo.co.in wrote:
> Right. It is much better to just to what the docs says.
> That extra curly brace makes the code a syntax error on
> other systems, and can be a runtime error on others.



Do you have any idea, why posix have designed push and pop in this way.
I was thinking like it would be similar to atexit . And really, it is
not like that.

ilko.k.v@gmail.com

2006-09-27, 1:21 pm


shaanxxx wrote:
> #include<stdio.h>
> #include<pthread.h>
> int main()
> {
> return 0;
> }
>
> void callCancelHandlerSubscribe (void *param)
> {
> printf("++++callCancelHandlerSubscribe+++\n");
> }
>
> void myfunc ()
> {
> pthread_cleanup_push(callCancelHandlerSu
bscribe, 0);
> return ;
> }
>
>
> Am I doing any thing wrong here ? i am not able to compile the above
> code .
>
> Here are error and compiler information :
>
> SHQ >> cc test.c -lpthread
> "test.c", line 21: syntax error before or at: <EOF>
> cc: acomp failed for test.c
> SHQ >> CC test.c -lpthread
> "test.c", line 21: Error: "}" expected instead of EOF.
> 1 Error(s) detected.
> SHQ >> cc -V
> cc: Sun WorkShop 6 update 2 C 5.3 2001/05/15
> usage: cc [ options] files. Use 'cc -flags' for details
> SHQ >> CC -V
> CC: Sun WorkShop 6 update 2 C++ 5.3 Patch 111685-19 2003/12/18


View
sample:http://www.cs.cf.ac.uk/Dave/C/node3...000000000000000
Part: "POSIX Cancellation"

raxitsheth2000@yahoo.co.in

2006-09-28, 1:39 am

really no idea, but 2 guess.

1=2E Why to use Macro Instead of Function (Adv. and DisAdv of Macro vs
Function)
2=2E Its better to read document( I have to disagree bcoz its against "0
learning curve") but in reallife its always good.

--
Cheers
Raxit Sheth

shaanxxx wrote:
> Nils O. Sel=E5sdal wrote:
st[vbcol=seagreen]
on[vbcol=seagreen]
>
>
> Do you have any idea, why posix have designed push and pop in this way.
> I was thinking like it would be similar to atexit . And really, it is
> not like that.


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com