Author Topic: if using //, it showed " error: expected expression before '/' token "  (Read 19048 times)

Offline gary8520

  • Single posting newcomer
  • *
  • Posts: 3
My OS is WIN7 64bit, using Code::Blocks 13.12!

it is part of my code:

76//    printf("請輸入共有幾個小組:");
77//    scanf("%u",&totalteam);
78//    fflush(stdin);
79//
80//    unsigned int *team = (int*) malloc( (totalteam + 2) * sizeof(int) );
81//    team[0] = totalteam;
82//    printf("現在要輸入小組的人數資料,\n要用問答的方式一組組輸入請按y,用檔案匯入請按其他。(y/其他)");
83//    choice = getch();
84//    printf("\n\n");
85//
86//    if(choice == 'y')
87//    {

It is line76 to line87

I wanted to skip many line of code, so I used Ctrl + Shift + C to make it as comment(about 300 lines)
but Build log show that:
C:\Users\user\Dropbox\座位表生成程式\main.c:76:1: error: expected expression before '/' token
C:\Users\user\Dropbox\座位表生成程式\main.c:77:1: error: expected expression before '/' token
C:\Users\user\Dropbox\座位表生成程式\main.c:78:1: error: expected expression before '/' token
C:\Users\user\Dropbox\座位表生成程式\main.c:79:1: error: expected expression before '/' token
C:\Users\user\Dropbox\座位表生成程式\main.c:81:1: error: expected expression before '/' token
C:\Users\user\Dropbox\座位表生成程式\main.c:82:1: error: expected expression before '/' token
C:\Users\user\Dropbox\座位表生成程式\main.c:83:1: error: expected expression before '/' token
C:\Users\user\Dropbox\座位表生成程式\main.c:84:1: error: expected expression before '/' token
C:\Users\user\Dropbox\座位表生成程式\main.c:85:1: error: expected expression before '/' token
C:\Users\user\Dropbox\座位表生成程式\main.c:161:1: error: expected expression before '/' token
etc...

It is not every line used // will be error.
If I compile this code in cmd (gcc main.c), it didn't show any error message.

I compiled other code which I used C:B 12.XX, it was no problem but now it cannot complie normaly.


what is the problem?

Thanks a lot!

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re:
« Reply #1 on: January 31, 2014, 06:18:06 am »
Don't use C++ comments with C. You have to use proper C comments: /* */
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline gary8520

  • Single posting newcomer
  • *
  • Posts: 3
Re: if using //, it showed " error: expected expression before '/' token "
« Reply #2 on: January 31, 2014, 07:03:09 am »
(this is the first time I heard that // is not proper comment in C :o )

Does any way that we can adjust comment(ctrl + shift + C) and uncomment(ctrl + shift + X) from // to /* */?

I just want to skip some section of my code temporarily.


Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: if using //, it showed " error: expected expression before '/' token "
« Reply #3 on: January 31, 2014, 09:11:21 am »
Does any way that we can adjust comment(ctrl + shift + C) and uncomment(ctrl + shift + X) from // to /* */?
Mmh... I'm afraid this is not possible, but you could file a feature request.

Hence /* ... */ is different: You can comment large code sections like this:
Code
/*
... large code section ...
... several lines of code ...
*/
So you only need 4 characters to enter. :)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline gary8520

  • Single posting newcomer
  • *
  • Posts: 3
Re: if using //, it showed " error: expected expression before '/' token "
« Reply #4 on: January 31, 2014, 09:34:23 am »
Does any way that we can adjust comment(ctrl + shift + C) and uncomment(ctrl + shift + X) from // to /* */?
Mmh... I'm afraid this is not possible, but you could file a feature request.

Hence /* ... */ is different: You can comment large code sections like this:
Code
/*
... large code section ...
... several lines of code ...
*/
So you only need 4 characters to enter. :)

I have known that ::) , but there is several box comment and stream comment in my code, it cannot just work as comment(ctrl + shift + C) that whole section become comment

Thanks!

Offline osdt

  • Multiple posting newcomer
  • *
  • Posts: 63
Re: if using //, it showed " error: expected expression before '/' token "
« Reply #5 on: January 31, 2014, 10:12:55 am »
(this is the first time I heard that // is not proper comment in C :o )
Compile for at least C99 to make them valid (gcc option --std=c99).

I just want to skip some section of my code temporarily.
You may want to use #if 0 to temporarily skip parts of the code:
Code
#if 0
    puts("this will be skipped"); /* comment */
    ...
#endif

- osdt
« Last Edit: January 31, 2014, 10:29:50 am by osdt »