News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Taking into account C99 standard

Started by Pavel_47, October 14, 2014, 01:01:22 PM

Previous topic - Next topic

Pavel_47

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.

Quiss

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.

stahta01

#2
Quote from: Quiss 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.

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.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

Quiss

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.

Pavel_47

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.

Pavel_47

Probable explanation - Code::Block processes .C files with "C compiler" rather than with "C++ compiler"
And C99 standard is for C++.
Correct ?

scarphin

Think in this way; if it was a standard for C++ then it would be named as C++99.

Pavel_47

There is no flag C++99 in the available options

oBFusCATed

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!]

Miguel Gimenez

You must put -std=c99 into Compiler settings -> Other options, not in Prebuild Steps

Pavel_47

Hello Mgimenez

Here is my source 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:
||=== 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

Jenna

This is not the content of the "Build log"-tab, but from "Build messages".

Quote from: Pavel_47 on November 17, 2014, 01:44:04 PM
..\..\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).

Pavel_47

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:
#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:
||=== 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




oBFusCATed

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!]

stahta01

#14
Quote from: oBFusCATed on November 17, 2014, 08:21:54 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.

C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]