Author Topic: Taking into account C99 standard  (Read 41986 times)

Offline Pavel_47

  • Multiple posting newcomer
  • *
  • Posts: 66
Taking into account C99 standard
« on: October 14, 2014, 01:01:22 pm »
Hello,

While trying to use the following construction:

for (int i = 0; i < numb_of_clients; i++)

I get the folllowing message:

udp_server_v0.c 54 error: 'for' loop initial declarations are only allowed in C99 mode
udp_server_v0.c 54 note: use option -std=c99 or -std=gnu99 to compile your code

I searched for these options in Settings-->Compiler-->Compiler Settings-->Global Compiler Settings-->Compiler Flags, but didn't find them.
Then I've tried to add them into Settings-->Compiler-->Compiler Settings-->Global Compiler Settings-->Other Options.

No any effect !

Thanks in advance.

Pavel.

Offline Quiss

  • Multiple posting newcomer
  • *
  • Posts: 76
Re: Taking into account C99 standard
« Reply #1 on: October 14, 2014, 02:59:35 pm »
Those will affect on new projects. For your current project, right click project name on the left pane(under Manager->Projects tab) and select Build Options.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Taking into account C99 standard
« Reply #2 on: October 15, 2014, 03:20:52 am »
Those will affect on new projects. For your current project, right click project name on the left pane(under Manager->Projects tab) and select Build Options.

The above is NOT true in most if not all cases.

He is likely changing the wrong global compiler.
He needs to verify the project is using the same CB Compiler as the one he changed.

EDIT: As found out later in this thread or another thread he is using a Custom makefile without any understanding of what it means in CB.

Tim S.
« Last Edit: November 19, 2014, 04:03:08 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Quiss

  • Multiple posting newcomer
  • *
  • Posts: 76
Re: Taking into account C99 standard
« Reply #3 on: October 15, 2014, 07:26:50 am »
I've just tried this and yes, you're right stahta01. Some years before, I don't remember exactly, I had that kind of problem but obviously it was from something else. Sorry for misinformation.

Offline Pavel_47

  • Multiple posting newcomer
  • *
  • Posts: 66
Re: Taking into account C99 standard
« Reply #4 on: October 30, 2014, 01:03:54 pm »
Hello stahta01,

I put option -std=c99 into Prebuild Steps (if I properly understood your suggestion)

Here is compilation output:
Running target pre-build steps
-std=c99
Execution of '-std=c99' in 'C:\Users\Pavel\Documents\Proj_EPFL\contiki-2.7\LoWPAN_EPFL\link_v1' failed.

Offline Pavel_47

  • Multiple posting newcomer
  • *
  • Posts: 66
Re: Taking into account C99 standard
« Reply #5 on: November 05, 2014, 02:44:28 pm »
Probable explanation - Code::Block processes .C files with "C compiler" rather than with "C++ compiler"
And C99 standard is for C++.
Correct ?

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Taking into account C99 standard
« Reply #6 on: November 05, 2014, 03:45:26 pm »
Think in this way; if it was a standard for C++ then it would be named as C++99.

Offline Pavel_47

  • Multiple posting newcomer
  • *
  • Posts: 66
Re: Taking into account C99 standard
« Reply #7 on: November 05, 2014, 04:09:38 pm »
There is no flag C++99 in the available options

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Taking into account C99 standard
« Reply #8 on: November 05, 2014, 06:48:24 pm »
There is no C++99, this is what scarphin told you. The standards are c++98,c++03,c++11,c++14.
But if any or all of these are supported by your compiler is up to your compiler and its current version you're using.
So check its documentation.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: Taking into account C99 standard
« Reply #9 on: November 05, 2014, 09:01:36 pm »
You must put -std=c99 into Compiler settings -> Other options, not in Prebuild Steps

Offline Pavel_47

  • Multiple posting newcomer
  • *
  • Posts: 66
Re: Taking into account C99 standard
« Reply #10 on: November 17, 2014, 01:44:04 pm »
Hello Mgimenez

Here is my source code:
Code
#include "contiki.h"
#include <stdio.h> /* For printf() */

void ssi0_isr()
{
}

/*---------------------------------------------------------------------------*/
PROCESS(hello_world_process, "Hello world process");
AUTOSTART_PROCESSES(&hello_world_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(hello_world_process, ev, data)
{
    PROCESS_BEGIN();

    for(int i=0; i < 10; i++)
    {
        printf("Hello, world\n");
    }
    PROCESS_END();
}

Here is compiler log:
Code
||=== Build: Debug in link_v1 (compiler: GNU GCC Compiler for ARM) ===|
test_cpp_v1.c||In function 'process_thread_hello_world_process':|
test_cpp_v1.c|16|error: 'for' loop initial declarations are only allowed in C99 mode|
test_cpp_v1.c|16|note: use option -std=c99 or -std=gnu99 to compile your code|
..\..\Makefile.include|234|recipe for target 'test_cpp_v1.co' failed|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|

Here is Compiler settings -> Other options (please see the snapshot).

Best Regards

Pavel

P.S. I also tried with -std=c99 ... the same result

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Taking into account C99 standard
« Reply #11 on: November 17, 2014, 05:37:11 pm »
This is not the content of the "Build log"-tab, but from "Build messages".

Code
..\..\Makefile.include|234|recipe for target 'test_cpp_v1.co' failed|
Is it a custom makefile project ?
If yes, the settings you make in compiler tab are ignored, because you do not use C::B's own build-system.
You have to make the needed changes inside the makefile or in the make-comamandline in the "Project -> Build options... -> Make options" (if your makefile supports this).

Offline Pavel_47

  • Multiple posting newcomer
  • *
  • Posts: 66
Re: Taking into account C99 standard
« Reply #12 on: November 17, 2014, 06:54:16 pm »
Hello Jens

Thank you for suggestions.
I've tried both (at least as I understood them)

1. Changing custom makefile ... I included "-std=c99" on the top of makefile:
Code
#DEFINES+=PROJECT_CONF_H=\"project-conf.h\"
-std=c99
all: test_cpp_v1
APPS=servreg-hack
CONTIKI=../..

UIP_CONF_IPV6=1
#SERVER_REPLY=1

CFLAGS+= -DUIP_CONF_IPV6_RPL

ifdef WITH_COMPOWER
APPS+=powertrace
CFLAGS+= -DCONTIKIMAC_CONF_COMPOWER=1 -DWITH_COMPOWER=1 -DQUEUEBUF_CONF_NUM=4
endif

ifdef SERVER_REPLY
CFLAGS+=-DSERVER_REPLY=$(SERVER_REPLY)
endif
ifdef PERIOD
CFLAGS+=-DPERIOD=$(PERIOD)
endif

include $(CONTIKI)/Makefile.include

Result: nothing changed - the build log is the same:
Code
||=== Build: Debug in link_v1 (compiler: GNU GCC Compiler for ARM) ===|
test_cpp_v1.c||In function 'process_thread_hello_world_process':|
test_cpp_v1.c|16|error: 'for' loop initial declarations are only allowed in C99 mode|
test_cpp_v1.c|16|note: use option -std=c99 or -std=gnu99 to compile your code|
..\..\Makefile.include|234|recipe for target 'test_cpp_v1.co' failed|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|

2. Changing make-commandlinein the "Project -> Build options... -> Make options"  ... instead of "$make -f $makefile" I've put "$make -std c99 -f $makefile".
After having run "Build" the "Build messages" window are rapidly filled with endless messages ... I was need to abort.

Regards

Pavel




Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Taking into account C99 standard
« Reply #13 on: November 17, 2014, 08:21:54 pm »
Sorry but you are changing settings randomly and you're expecting it to magically work.
I have to disappoint you - it won't sooner or later you'll hit the road block.
So if you want to have any success in what you're doing - start reading on Makefiles, compilers, linkers and so on.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Taking into account C99 standard
« Reply #14 on: November 17, 2014, 08:47:03 pm »
...
So if you want to have any success in what you're doing - start reading on Makefiles, compilers, linkers and so on.

I agree with the above; I also suggest you STOP asking about how to fix the Contiki Makefile on this site!

I suggest a site that supports questions on how to write or modify makefiles or a site supporting compiling Contiki.

Edit2: You might try the C Board site http://cboard.cprogramming.com/forum.php

Tim S.

« Last Edit: November 17, 2014, 08:51:15 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org