* RE: Mysterious syntax error
@ 2005-01-27 1:39 Dave Gotwisner
2005-01-27 1:42 ` corey taylor
0 siblings, 1 reply; 5+ messages in thread
From: Dave Gotwisner @ 2005-01-27 1:39 UTC (permalink / raw)
To: Ian Pilcher, gcc-help
I am not sure where your file was generated, and can't tell from the
listing (it looks correct), but if the file was initially generated on
Windows and binary ftp'ed over to a Unix box before it was compiled,
there might be a ^Z at the end of the file (or a '\0'). If you OD -x
the source and look at the output at the end, it should be glaringly
obvious. Also, I have seen some compilers barf if there is no \n at the
end of the last line, not sure how GCC behaves (it used to croak, years
ago).
-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On
Behalf Of Ian Pilcher
Sent: Wednesday, January 26, 2005 5:25 PM
To: gcc-help@gcc.gnu.org
Subject: Mysterious syntax error
Apologies in advance if this is a *really* stupid question. I'm trying
to compile the code below on Fedora Core 3 (gcc-3.4.2-6.fc3), and it's
telling me I've got a syntax error that I just can't see.
[pilcher@home temp]$ gcc -c aarg.c
aarg.c: In function `alarm_thread':
aarg.c:82: error: syntax error at end of input
I've stared at this long enough to know that, if there is an error in
the code, I'm not going to find it. I'd really appreciate it if someone
with smarter eyes could take a look.
Thanks!
#include <stdlib.h>
#include <signal.h>
#include <errno.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/time.h>
typedef struct pt_alarm_s pt_alarm_t;
typedef struct pt_alarmattr_s pt_alarmattr_t;
enum pt_alarm_state
{
PT_ALARM_IDLE,
PT_ALARM_SET,
PT_ALARM_RUNNING,
PT_ALARM_CANCELED,
PT_ALARM_ERROR
};
struct pt_alarm_s
{
pthread_t target_tid;
pthread_t alarm_tid;
pthread_mutex_t mutex;
pthread_cond_t cond;
struct timespec timeout;
enum pt_alarm_state state;
};
struct pt_alarmattr_s
{
unsigned char filler[1];
};
/***********************************************************************
*
* alarm thread
*
**********************************************************************/
static void cleanup_alarm_mutex(void *arg)
{
pt_alarm_t *const alarm = arg;
pthread_mutex_unlock(&alarm->mutex);
}
static void *alarm_thread(void *arg)
{
pt_alarm_t *const alarm = arg;
pthread_cleanup_push(cleanup_alarm_mutex, arg);
pthread_mutex_lock(&alarm->mutex);
while (1)
{
int pt_errno;
while (alarm->state != PT_ALARM_SET)
pthread_cond_wait(&alarm->cond, &alarm->mutex);
alarm->state = PT_ALARM_RUNNING;
pt_errno = 0;
while (alarm->state != PT_ALARM_CANCELED &&
pt_errno != ETIMEDOUT)
{
pt_errno = pthread_cond_timedwait(&alarm->cond,
&alarm->mutex, &alarm->timeout);
}
if (alarm->state != PT_ALARM_CANCELED)
pthread_kill(alarm->target_tid, SIGALRM);
}
return NULL; /* should never get here! */
}
--
========================================================================
Ian Pilcher i.pilcher@comcast.net
========================================================================
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Mysterious syntax error
2005-01-27 1:39 Mysterious syntax error Dave Gotwisner
@ 2005-01-27 1:42 ` corey taylor
0 siblings, 0 replies; 5+ messages in thread
From: corey taylor @ 2005-01-27 1:42 UTC (permalink / raw)
To: gcc-help
That kind of error shouldn't result in the syntax error inside the
function like he is showing.
corey
On Wed, 26 Jan 2005 17:39:13 -0800, Dave Gotwisner
<Dave.Gotwisner@harmonicinc.com> wrote:
> I am not sure where your file was generated, and can't tell from the
> listing (it looks correct), but if the file was initially generated on
> Windows and binary ftp'ed over to a Unix box before it was compiled,
> there might be a ^Z at the end of the file (or a '\0'). If you OD -x
> the source and look at the output at the end, it should be glaringly
> obvious. Also, I have seen some compilers barf if there is no \n at the
> end of the last line, not sure how GCC behaves (it used to croak, years
> ago).
>
> -----Original Message-----
> From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On
> Behalf Of Ian Pilcher
> Sent: Wednesday, January 26, 2005 5:25 PM
> To: gcc-help@gcc.gnu.org
> Subject: Mysterious syntax error
>
> Apologies in advance if this is a *really* stupid question. I'm trying
> to compile the code below on Fedora Core 3 (gcc-3.4.2-6.fc3), and it's
> telling me I've got a syntax error that I just can't see.
>
> [pilcher@home temp]$ gcc -c aarg.c
> aarg.c: In function `alarm_thread':
> aarg.c:82: error: syntax error at end of input
>
> I've stared at this long enough to know that, if there is an error in
> the code, I'm not going to find it. I'd really appreciate it if someone
> with smarter eyes could take a look.
>
> Thanks!
>
> #include <stdlib.h>
> #include <signal.h>
> #include <errno.h>
>
> #include <unistd.h>
> #include <pthread.h>
> #include <sys/time.h>
>
> typedef struct pt_alarm_s pt_alarm_t;
> typedef struct pt_alarmattr_s pt_alarmattr_t;
>
> enum pt_alarm_state
> {
> PT_ALARM_IDLE,
> PT_ALARM_SET,
> PT_ALARM_RUNNING,
> PT_ALARM_CANCELED,
> PT_ALARM_ERROR
> };
>
> struct pt_alarm_s
> {
> pthread_t target_tid;
> pthread_t alarm_tid;
>
> pthread_mutex_t mutex;
> pthread_cond_t cond;
> struct timespec timeout;
> enum pt_alarm_state state;
> };
>
> struct pt_alarmattr_s
> {
> unsigned char filler[1];
> };
>
> /***********************************************************************
> *
> * alarm thread
> *
>
> **********************************************************************/
>
> static void cleanup_alarm_mutex(void *arg)
> {
> pt_alarm_t *const alarm = arg;
>
> pthread_mutex_unlock(&alarm->mutex);
> }
>
> static void *alarm_thread(void *arg)
> {
> pt_alarm_t *const alarm = arg;
>
> pthread_cleanup_push(cleanup_alarm_mutex, arg);
> pthread_mutex_lock(&alarm->mutex);
>
> while (1)
> {
> int pt_errno;
>
> while (alarm->state != PT_ALARM_SET)
> pthread_cond_wait(&alarm->cond, &alarm->mutex);
>
> alarm->state = PT_ALARM_RUNNING;
>
> pt_errno = 0;
>
> while (alarm->state != PT_ALARM_CANCELED &&
> pt_errno != ETIMEDOUT)
> {
> pt_errno = pthread_cond_timedwait(&alarm->cond,
> &alarm->mutex, &alarm->timeout);
> }
>
> if (alarm->state != PT_ALARM_CANCELED)
> pthread_kill(alarm->target_tid, SIGALRM);
> }
>
> return NULL; /* should never get here! */
> }
>
> --
> ========================================================================
> Ian Pilcher i.pilcher@comcast.net
> ========================================================================
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Mysterious syntax error
2005-01-27 1:39 ` Guillaume Autran
@ 2005-01-27 2:10 ` Ian Pilcher
0 siblings, 0 replies; 5+ messages in thread
From: Ian Pilcher @ 2005-01-27 2:10 UTC (permalink / raw)
To: gcc-help; +Cc: gautran
Guillaume Autran wrote:
> pthread_cleanup_push(...) ==> pthread_cleanup_pop(...)
>
> If you use one, you *MUST* use the other one.
>
> At the end of your function:
> static void *alarm_thread(void *arg)
>
> Add:
> pthread_cleanup_pop(0);
>
Thank you! That's one man page it doesn't pay to skim!
--
========================================================================
Ian Pilcher i.pilcher@comcast.net
========================================================================
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Mysterious syntax error
2005-01-27 1:32 Ian Pilcher
@ 2005-01-27 1:39 ` Guillaume Autran
2005-01-27 2:10 ` Ian Pilcher
0 siblings, 1 reply; 5+ messages in thread
From: Guillaume Autran @ 2005-01-27 1:39 UTC (permalink / raw)
To: Ian Pilcher; +Cc: gcc-help
pthread_cleanup_push(...) ==> pthread_cleanup_pop(...)
If you use one, you *MUST* use the other one.
At the end of your function:
static void *alarm_thread(void *arg)
Add:
pthread_cleanup_pop(0);
Guillaume.
Ian Pilcher wrote:
> Apologies in advance if this is a *really* stupid question. I'm trying
> to compile the code below on Fedora Core 3 (gcc-3.4.2-6.fc3), and it's
> telling me I've got a syntax error that I just can't see.
>
> [pilcher@home temp]$ gcc -c aarg.c
> aarg.c: In function `alarm_thread':
> aarg.c:82: error: syntax error at end of input
>
> I've stared at this long enough to know that, if there is an error in
> the code, I'm not going to find it. I'd really appreciate it if someone
> with smarter eyes could take a look.
>
> Thanks!
>
>
> #include <stdlib.h>
> #include <signal.h>
> #include <errno.h>
>
> #include <unistd.h>
> #include <pthread.h>
> #include <sys/time.h>
>
> typedef struct pt_alarm_s pt_alarm_t;
> typedef struct pt_alarmattr_s pt_alarmattr_t;
>
>
> enum pt_alarm_state
> {
> PT_ALARM_IDLE,
> PT_ALARM_SET,
> PT_ALARM_RUNNING,
> PT_ALARM_CANCELED,
> PT_ALARM_ERROR
> };
>
> struct pt_alarm_s
> {
> pthread_t target_tid;
> pthread_t alarm_tid;
>
> pthread_mutex_t mutex;
> pthread_cond_t cond;
> struct timespec timeout;
> enum pt_alarm_state state;
> };
>
> struct pt_alarmattr_s
> {
> unsigned char filler[1];
> };
>
>
> /***********************************************************************
> *
> * alarm thread
> *
> **********************************************************************/
>
> static void cleanup_alarm_mutex(void *arg)
> {
> pt_alarm_t *const alarm = arg;
>
> pthread_mutex_unlock(&alarm->mutex);
> }
>
> static void *alarm_thread(void *arg)
> {
> pt_alarm_t *const alarm = arg;
>
> pthread_cleanup_push(cleanup_alarm_mutex, arg);
> pthread_mutex_lock(&alarm->mutex);
>
> while (1)
> {
> int pt_errno;
>
> while (alarm->state != PT_ALARM_SET)
> pthread_cond_wait(&alarm->cond, &alarm->mutex);
>
> alarm->state = PT_ALARM_RUNNING;
>
> pt_errno = 0;
>
> while (alarm->state != PT_ALARM_CANCELED &&
> pt_errno != ETIMEDOUT)
> {
> pt_errno = pthread_cond_timedwait(&alarm->cond,
> &alarm->mutex, &alarm->timeout);
> }
>
> if (alarm->state != PT_ALARM_CANCELED)
> pthread_kill(alarm->target_tid, SIGALRM);
> }
>
> return NULL; /* should never get here! */
> }
>
--
=======================================
Guillaume Autran
IMAGO Laboratory - Department of Computing and Information Science
University of Guelph
Tel: (519)824-4120 ext:56645
E-mail: gautran@draco.cis.uoguelph.ca
Web: http://draco.cis.uoguelph.ca/~gautran
=======================================
^ permalink raw reply [flat|nested] 5+ messages in thread
* Mysterious syntax error
@ 2005-01-27 1:32 Ian Pilcher
2005-01-27 1:39 ` Guillaume Autran
0 siblings, 1 reply; 5+ messages in thread
From: Ian Pilcher @ 2005-01-27 1:32 UTC (permalink / raw)
To: gcc-help
Apologies in advance if this is a *really* stupid question. I'm trying
to compile the code below on Fedora Core 3 (gcc-3.4.2-6.fc3), and it's
telling me I've got a syntax error that I just can't see.
[pilcher@home temp]$ gcc -c aarg.c
aarg.c: In function `alarm_thread':
aarg.c:82: error: syntax error at end of input
I've stared at this long enough to know that, if there is an error in
the code, I'm not going to find it. I'd really appreciate it if someone
with smarter eyes could take a look.
Thanks!
#include <stdlib.h>
#include <signal.h>
#include <errno.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/time.h>
typedef struct pt_alarm_s pt_alarm_t;
typedef struct pt_alarmattr_s pt_alarmattr_t;
enum pt_alarm_state
{
PT_ALARM_IDLE,
PT_ALARM_SET,
PT_ALARM_RUNNING,
PT_ALARM_CANCELED,
PT_ALARM_ERROR
};
struct pt_alarm_s
{
pthread_t target_tid;
pthread_t alarm_tid;
pthread_mutex_t mutex;
pthread_cond_t cond;
struct timespec timeout;
enum pt_alarm_state state;
};
struct pt_alarmattr_s
{
unsigned char filler[1];
};
/***********************************************************************
*
* alarm thread
*
**********************************************************************/
static void cleanup_alarm_mutex(void *arg)
{
pt_alarm_t *const alarm = arg;
pthread_mutex_unlock(&alarm->mutex);
}
static void *alarm_thread(void *arg)
{
pt_alarm_t *const alarm = arg;
pthread_cleanup_push(cleanup_alarm_mutex, arg);
pthread_mutex_lock(&alarm->mutex);
while (1)
{
int pt_errno;
while (alarm->state != PT_ALARM_SET)
pthread_cond_wait(&alarm->cond, &alarm->mutex);
alarm->state = PT_ALARM_RUNNING;
pt_errno = 0;
while (alarm->state != PT_ALARM_CANCELED &&
pt_errno != ETIMEDOUT)
{
pt_errno = pthread_cond_timedwait(&alarm->cond,
&alarm->mutex, &alarm->timeout);
}
if (alarm->state != PT_ALARM_CANCELED)
pthread_kill(alarm->target_tid, SIGALRM);
}
return NULL; /* should never get here! */
}
--
========================================================================
Ian Pilcher i.pilcher@comcast.net
========================================================================
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2005-01-27 2:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-27 1:39 Mysterious syntax error Dave Gotwisner
2005-01-27 1:42 ` corey taylor
-- strict thread matches above, loose matches on Subject: below --
2005-01-27 1:32 Ian Pilcher
2005-01-27 1:39 ` Guillaume Autran
2005-01-27 2:10 ` Ian Pilcher
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).