Using #define in C code

Hi,

I faced some issue using #define in C code. It was ok in C++ code. An example is below:

#define NO_OF_INPUTS 3

int connections[NO_OF_INPUTS];

I was not able to compile the code in a C file in B&R studio. Is this an existing issue?

Thanks and Regards,

Kenneth

Hi Kenneth,

if you are facing problems like that you should ALWAYS tell us what version and what IDE you are using.

E.g. there is NO “B&R studio”. We have “Automation Studio” or “Automation Studio Code”. Versions range from 2.x to 6.x with GCC versions up to 11.3.0 . What are you referring to?

Also from the snippet above we cannot determine WHERE in your code the statements are placed. Maybe they are located in the wrong position?

An example with Automation Studio 6.3.1.32 and gcc V11.3.0 compiles without any errors:

#include <bur/plctypes.h>

#ifdef _DEFAULT_INCLUDES
   #include <AsDefault.h>
#endif

#define NO_OF_INPUTS 3
int connections[NO_OF_INPUTS];

void _CYCLIC ProgramCyclic(void)
{

}
1 Like

Hi Christian,

Thanks for your inputs. I am using Automation Studio 4.7.2.98. Could it be due to the Automation Studio version?

Regards,

Kenneth

This version is almost 6 years old.

To you have any specific needs for this version?

Older versions typically have problems with modern operating systems (e.g. Windows 11).

I would suggest Automation Studio 4.12 (if you have older hardware) or Version 6.3 (if you have up to date hardware).

Checked with 4.7.2.98 and gcc V4.1.2.

Works like a charm.

Do you mix C and C++ code?

------------- Building project FourSevenProject, configuration Config1 -------------
Analyzing project …
Generating header files …
Generating archive files …
Compiling C:\Users\bauerc\Documents\AutomationStudio\47\FourSevenProject\Logical\Program\Cyclic.c …
Compiling C:\BrAutomation\AS47\AS47\AS\GnuInst\V4.1.2\arm-elf\include\bur_bur_pvdef.c …
Linking C:\Users\bauerc\Documents\AutomationStudio\47\FourSevenProject\Temp\Objects\Config1\X20CP0411\Program\a.out …
Building program “Program” as “Program” …
Build: 0 error(s), 0 warning(s)

1 Like

Hi Christian,

Apologies for the confusion. The error was due to a stray semi-colon in my #define statement. (eg. #define NO_OF_INPUTS 3;) It is working now after removing the semicolon at the end.

Regards,

Kenneth