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

C expects one expression ?

P: 31
I hope you understand my poor english

This is my function (it used to return int), I got the same error when I compiled it for first time (then it was in the ***** marked line), so I started to comment one by one trying to allocate my fault... i couldn't:
Expand|Select|Wrap|Line Numbers
  1. void manage_data( TEntity * inEntity, TState inFromState, TEvent inEvent, TEventArgs * inArgs )
  2. {
  3. //    arguments *auxArgs;
  4. //    int rc = AUTOMAT_OK;
  5. //    char aux[4];
  6.  
  7. //    auxArgs=inArgs;
  8. //    auxArgs->trama.flag_s = 62;
  9. /*    auxArgs->trama.address = 0x69;
  10. //    auxArgs->trama.control = 4;
  11.  
  12. //    memset(auxArgs->trama.data,'\0',MAX);
  13. //    strcpy(auxArgs->trama.data,auxArgs->paquete.data);
  14. *****    //si cabe n, se incluye en la trama
  15.  
  16.     if (strlen(auxArgs->trama.data)<256)//261-(num(4)+ ~(1) + '/0'(1))
  17.     {
  18.         strcat(auxArgs->trama.data,"~");//se escribe una virgulilla
  19.         snprintf(aux,4,"%d",auxArgs->paquete.n);//se almacena el número de caracteres leídos
  20.         strcat(auxArgs->trama.data,aux);
  21.     }
  22.     strcat(auxArgs->trama.data,"\0");
  23.  
  24.     auxArgs->trama.FCS1 = 0;
  25.     auxArgs->trama.FCS2 = 0;
  26.     auxArgs->flag_e = 62;    
  27. */
  28.  // return rc;
  29. }
----------------------------------------------------------------------
"$gcc -g -Wall -ansi -I . TX_automat_SW.c" returns:


TX_automat_SW.c: In function ‘manage_data’:
TX_automat_SW.c:83: error: expected expression before ‘/’ token
TX_automat_SW.c:84: error: expected expression before ‘/’ token
TX_automat_SW.c:85: error: expected expression before ‘/’ token
TX_automat_SW.c:87: error: expected expression before ‘/’ token
TX_automat_SW.c:88: error: expected expression before ‘/’ token
TX_automat_SW.c:108: error: expected expression before ‘/’ token


I just can't figure what is it expecting...
May 30 '07 #1
Share this Question
Share on Google+
7 Replies


P: 31
By the way.

Other functions have the same header

type name( TEntity * inEntity, TState inFromState, TEvent inEvent, TEventArgs * inArgs )

and work properly
May 30 '07 #2

Savage
Expert 100+
P: 1,764
By the way.

Other functions have the same header

type name( TEntity * inEntity, TState inFromState, TEvent inEvent, TEventArgs * inArgs )

and work properly
Void functions cannot return a value.

If u wish to return a int make a function type to be a int.

Savage
May 30 '07 #3

P: 31
Void functions cannot return a value.

If u wish to return a int make a function type to be a int.

Savage

Function returns int, I wrote void because I commented the return instruction too.

OK, by deleting every single-line comment, i got it working.

Can anyone explain me it?



That .c file implements his homonym .h, which is as follows:
___________________________________
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <unistd.h>
  5.  
  6. #include <IFTI_P2_automat.h>
  7.  
  8. #define    REACHED_EOF        3
  9. #define MAX 261
  10.  
  11.  
  12. typedef struct{
  13.      char data[MAX];
  14.      int n;
  15. }packet;
  16.  
  17. typedef struct
  18. {
  19.      char flag_s;
  20.      char address;
  21.      unsigned char control;
  22.      char data[MAX];
  23.      unsigned char FCS1;
  24.      unsigned char FCS2;
  25.      char flag_e;
  26. }frame;
  27.  
  28. typedef struct{
  29.     frame trama;
  30.     packet paquete;
  31.     FILE* file;
  32.     int tty;
  33. }arguments;
  34.  
  35.  
  36. /* ------------------------------------------------------------ 
  37.  * State definitions
  38.  * ------------------------------------------------------------ */
  39. enum {
  40.     TX_STATE_INITIAL = AUTOMAT_INITIAL_STATE,
  41.     TX_STATE_ERROR,
  42.     TX_STATE_READING,
  43.     TX_STATE_FRAMING,
  44.     TX_STATE_WAITING
  45. };
  46.  
  47. #define TX_STATE_TEXT(X) \
  48. (X==TX_STATE_INITIAL)? "TX_STATE_INITIAL" : \
  49. (X==TX_STATE_ERROR)? "TX_STATE_ERROR" : \
  50. (X==TX_STATE_READING)? "TX_STATE_READING" : \
  51. (X==TX_STATE_FRAMING)? "TX_STATE_FRAMING" : \
  52. (X==TX_STATE_WAITING)? "TX_STATE_WAITING" : \
  53. "UNDEF"
  54.  
  55.  
  56. /* ------------------------------------------------------------ 
  57.  * Event definitions
  58.  * ------------------------------------------------------------ */
  59. enum {
  60.   TX_EV_OPERATIVE = 1,
  61.   TX_EV_READOK,
  62.   TX_EV_FRAMED,
  63.   TX_EV_ACK_RECEIVED,
  64. };
  65.  
  66. /* ------------------------------------------------------------ 
  67.  * Action definitions
  68.  * ------------------------------------------------------------ */
  69. TAutomat * TX_automat_SW_define( );
  70.  
  71. int internal_error(    TEntity * inEntity,
  72.             TState inFromState,
  73.             TEvent inEvent,
  74.             TEventArgs * inArgs );
  75.  
  76. int read_data(    TEntity * inEntity,
  77.             TState inFromState,
  78.             TEvent inEvent,
  79.             TEventArgs * inArgs );
  80.  
  81. int manage_data(    TEntity * inEntity,
  82.             TState inFromState,
  83.             TEvent inEvent,
  84.             TEventArgs * inArgs );
  85.  
  86. int send_data_wait_response(    TEntity * inEntity,
  87.             TState inFromState,
  88.             TEvent inEvent,
  89.             TEventArgs * inArgs );
  90.  
  91.  
  92.  
________________________
Thanks for your attention
May 30 '07 #4

Savage
Expert 100+
P: 1,764
I think that's becasue ur comment styles.

U are mixing c and c++ commenting styles

Savage
May 30 '07 #5

Banfa
Expert Mod 5K+
P: 8,916
I think that's becasue ur comment styles.

U are mixing c and c++ commenting styles
Mixing them is OK, although possibly bad practice, I suspect it is because they are nested.

i.e.

Expand|Select|Wrap|Line Numbers
  1. /* Look I have started a multi-line comment
  2.  
  3.  
  4. // and now I have put in a single line comment
  5.  
  6. and now I am ending the multi-line comment */
  7.  
It is never a good idea to nest comments, confusion results.
May 30 '07 #6

Savage
Expert 100+
P: 1,764
Mixing them is OK, although possibly bad practice, I suspect it is because they are nested.

i.e.

Expand|Select|Wrap|Line Numbers
  1. /* Look I have started a multi-line comment
  2.  
  3.  
  4. // and now I have put in a single line comment
  5.  
  6. and now I am ending the multi-line comment */
  7.  
It is never a good idea to nest comments, confusion results.
So, as we can see it's not OK.

Savage
May 30 '07 #7

P: 31
I found my mistake.

It's possible to mix this type of comments (i've done it so many times),
you can do it, but if you do, you can't try to compile using the -ansi flag in gcc...

Anyway, i'll try not to do it again. Thank you for your replies
May 31 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.