I'm getting loads of errors like these:
gfx.h:48: error: syntax error before 'buffer'
gfx.h:48: warning: type defaults to 'int' in declaration of 'buffer'
gfx.h:48: warning: data definition has no type or storage class
gfx.h:73: error: syntax error before 'uint16_t'
gfx.h:73: warning: no semicolon at end of struct or union
gfx.h:74: warning: type defaults to 'int' in declaration of 'visible_lines_per_frame'
gfx.h:74: warning: data definition has no type or storage class
...
I'm a bit tired, so I can't figure out what could be causing these.
This is the definition of buffer (starting at line 43, going to line 57):
/* 8-bit architecture (not yet used.) */
#if PROC_BIT_SIZE == 8
uint8_t buffer[GFX_SIZE];
# define GFX_PIXEL_ADDR(x,y) (x / 8) + (y * (GFX_WIDTH / 8))
/* 16-bit architecture: dsPIC */
#elif PROC_BIT_SIZE == 16
uint16_t buffer[GFX_SIZE / 2];
# define GFX_PIXEL_ADDR(x,y) (x / 16) + (y * (GFX_WIDTH / 16))
/* 32-bit architecture: AVR32(?), STM32 */
#elif PROC_BIT_SIZE == 32
uint32_t buffer[GFX_SIZE / 4];
# define GFX_PIXEL_ADDR(x,y) (x / 32) + (y * (GFX_WIDTH / 32))
/* Other, unknown bit size.*/
#else
# error "processor bit size not supported"
#endif
(It's designed to support multiple architectures 8-bit MCUs to 32-bit MCUs.)
I've defined uint8_t etc. because the GCC I'm using doesn't seem to have a stdint.h header.
Here is how I have defined uint8_t etc.
/*
* stdint.h support.
* If your compiler has stdint.h, uncomment HAS_STDINT.
*/
//#define HAS_STDINT
#ifndef HAS_STDINT
// D'oh, compiler doesn't support STDINT, so create our own,
// 'standard' integers.
# if PROC_BIT_SIZE == 8 || PROC_BIT_SIZE == 16
typedef char int8_t;
typedef int int16_t;
typedef long int32_t;
typedef long long int64_t;
typedef unsigned char uint8_t;
typedef unsigned int uint16_t;
typedef unsigned long uint32_t;
typedef unsigned long long uint64_t;
# elif PROC_BIT_SIZE == 32
typedef char int8_t;
typedef short int16_t;
typedef int int32_t; // usually int is 32 bits on 32 bit processors, but this may need checking
typedef long int64_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long uint64_t;
# endif
#else
# include <stdint.h>
#endif
The warning: no semicolon at end of struct or union implies that you've left a semicolon off at the end of a struct or union defined earlier in the same file, or in another header that was included earlier. This would result in malformed statements such as:
struct S { ... } uint8_t buffer[GFX_SIZE];
I apparently have solved my problem.
My mistake was to not declare PROC_BIT_SIZE before the "typedef" definitions of uint8_t and friends. The preprocessor therefore ignored the declarations, causing the error.
Just a blunder of my own making.
Related
I am trying to build NASA cFS version 6.5 which uses 32bit applications on a 64 bit Jetson TX2 running Ubuntu.
I was getting the error "gcc: error: unrecognized command line option -m32".
I tried installing the gcc-multilib but I get:
Package gcc-multilib is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source
I tried looking for other packages using apt search gcc-multilib and I installed:
gcc-multilib-arm-linux-gnueabi
gcc-multilib-arm-linux-gnueabihf
gcc-multilib-x86-64-linux-gnu
gcc-multilib-x86-64-linux-gnux32
I know there's ones I probably don't need to install but I looked everywhere for a solution and couldn't find any.
I tried uncommenting all the lines in the sources.list, running sudo apt-get update and then and then trying to install but still no success.
Any help?
EDIT:
Okay so I removed the -m32 option from the cmake files that have it and tried to compile and I got a whole bunch of errors ranging from typedef erorrs to missing ; and others, not gonna list all of them because they're probably over 100 errors, but the first error I get is:
/home/deployer/CFS-101.initial/osal/src/os/inc/common_types.h:285:5: error: #error undefined processor
So I went the common_types.h and this is what it contains:
#ifndef _common_types_
#define _common_types_
#ifdef __cplusplus
extern "C" {
#endif
/*
** Includes
*/
/*
** Macro Definitions
*/
/*
** Condition = TRUE is ok, Condition = FALSE is error
*/
#define CompileTimeAssert(Condition, Message) typedef char Message[(Condition) ? 1 : -1]
/*
** Define compiler specific macros
** The __extension__ compiler pragma is required
** for the uint64 type using GCC with the ANSI C90 standard.
** Other macros can go in here as needed, for example alignment
** pragmas.
**
** NOTE: The white-box (coverage) unit testing may need to disable
** these extra attributes. These test builds define the OSAPI_NO_SPECIAL_ATTRIBS
** macro to disable this.
*/
#if defined (__GNUC__) && !defined(OSAPI_NO_SPECIAL_ATTRIBS)
#define _EXTENSION_ __extension__
#define OS_PACK __attribute__ ((packed))
#define OS_ALIGN(n) __attribute__((aligned(n)))
#define OS_USED __attribute__((used))
#define OS_PRINTF(n,m) __attribute__ ((format (printf, n, m)))
#else
#define _EXTENSION_
#define OS_PACK
#define OS_ALIGN(n)
#define OS_USED
#define OS_PRINTF(n,m)
#endif
/*
* If the host system has a ISO C99 standard stdint header file, prefer it.
* This ensures that fixed-width types are correct including on 64-bit systems.
*/
#if defined(_HAVE_STDINT_)
#include <stdint.h>
#include <stddef.h>
/*
* NOTE - NOT DEFINING STRUCT_LOW_BIT_FIRST or STRUCT_HIGH_BIT_FIRST
* We should not make assumptions about the bit order here
*/
typedef uint8_t osalbool;
typedef int8_t int8;
typedef int16_t int16;
typedef int32_t int32;
typedef int64_t int64;
typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef uint64_t uint64;
typedef intptr_t intptr;
typedef uintptr_t cpuaddr;
typedef size_t cpusize;
typedef ptrdiff_t cpudiff;
/*
* Fall back to default integer type maps -
* These definitions assume a 32-bit processor
*/
#elif defined(_ix86_) || defined (__i386__)
/* ----------------------- Intel x86 processor family -------------------------*/
/* Little endian */
#undef _STRUCT_HIGH_BIT_FIRST_
#define _STRUCT_LOW_BIT_FIRST_
typedef unsigned char osalbool;
typedef signed char int8;
typedef short int int16;
typedef long int int32;
_EXTENSION_ typedef long long int int64;
typedef unsigned char uint8;
typedef unsigned short int uint16;
typedef unsigned long int uint32;
_EXTENSION_ typedef unsigned long long int uint64;
typedef unsigned long int cpuaddr;
typedef unsigned long int cpusize;
typedef long int cpudiff;
#elif defined (_ix64_) || defined (__x86_64__)
/* ----------------------- Intel/AMD x64 processor family -------------------------*/
/* Little endian */
#undef _STRUCT_HIGH_BIT_FIRST_
#define _STRUCT_LOW_BIT_FIRST_
typedef unsigned char osalbool;
typedef signed char int8;
typedef short int int16;
typedef int int32;
typedef long int int64;
typedef unsigned char uint8;
typedef unsigned short int uint16;
typedef unsigned int uint32;
typedef unsigned long int uint64;
typedef unsigned long int cpuaddr;
typedef unsigned long int cpusize;
typedef long int cpudiff;
#elif defined(__PPC__) || defined (__ppc__)
/* ----------------------- Motorola Power PC family ---------------------------*/
/* The PPC can be programmed to be big or little endian, we assume native */
/* Big endian */
#define _STRUCT_HIGH_BIT_FIRST_
#undef _STRUCT_LOW_BIT_FIRST_
typedef unsigned char osalbool;
typedef signed char int8;
typedef short int int16;
typedef long int int32;
_EXTENSION_ typedef long long int int64;
typedef unsigned char uint8;
typedef unsigned short int uint16;
typedef unsigned long int uint32;
_EXTENSION_ typedef unsigned long long int uint64;
typedef unsigned long int cpuaddr;
typedef unsigned long int cpusize;
typedef long int cpudiff;
#elif defined(_m68k_) || defined(__m68k__)
/* ----------------------- Motorola m68k/Coldfire family ---------------------------*/
/* Big endian */
#define _STRUCT_HIGH_BIT_FIRST_
#undef _STRUCT_LOW_BIT_FIRST_
typedef unsigned char osalbool;
typedef signed char int8;
typedef short int int16;
typedef long int int32;
_EXTENSION_ typedef long long int int64;
typedef unsigned char uint8;
typedef unsigned short int uint16;
typedef unsigned long int uint32;
_EXTENSION_ typedef unsigned long long int uint64;
typedef unsigned long int cpuaddr;
typedef unsigned long int cpusize;
typedef long int cpudiff;
#elif defined (__ARM__) || defined(__arm__)
/* ----------------------- ARM processor family -------------------------*/
/* Little endian */
#undef _STRUCT_HIGH_BIT_FIRST_
#define _STRUCT_LOW_BIT_FIRST_
typedef unsigned char osalbool;
typedef signed char int8;
typedef short int int16;
typedef long int int32;
_EXTENSION_ typedef long long int int64;
typedef unsigned char uint8;
typedef unsigned short int uint16;
typedef unsigned long int uint32;
_EXTENSION_ typedef unsigned long long int uint64;
typedef unsigned long int cpuaddr;
typedef unsigned long int cpusize;
typedef long int cpudiff;
#elif defined(__SPARC__) || defined (_sparc_)
/* ----------------------- SPARC/LEON family ---------------------------*/
/* SPARC Big endian */
#define _STRUCT_HIGH_BIT_FIRST_
#undef _STRUCT_LOW_BIT_FIRST_
typedef unsigned char osalbool;
typedef signed char int8;
typedef short int int16;
typedef long int int32;
_EXTENSION_ typedef long long int int64;
typedef unsigned char uint8;
typedef unsigned short int uint16;
typedef unsigned long int uint32;
_EXTENSION_ typedef unsigned long long int uint64;
typedef unsigned long int cpuaddr;
typedef unsigned long int cpusize;
typedef long int cpudiff;
#else /* not any of the above */
#error undefined processor
#endif /* processor types */
/*
* Boolean type for compatibility --
*
* Note it is a bad idea to typedef "bool" or "boolean" -- MANY other projects
* and libraries also define a boolean type due to the lack of a standard bool in C89.
* But calling it simply "bool" or "boolean" almost guarantees a namespace conflict
* if trying to use OSAL with one of those other existing projects.
*
* RTEMS 4.11 no longer defines boolean type by default (deprecated) probably also
* due to the high likelihood of name conflicts.
*
* In order to preserve compatibility for apps written against prior versions of
* OSAL, the name "boolean" is typedefed as well, but this may be turned off
* in a future version whenever appropriate.
*/
#if (!defined(_USING_RTEMS_INCLUDES_) || !defined(RTEMS_DEPRECATED_TYPES))
typedef osalbool boolean;
#endif
#ifndef NULL /* pointer to nothing */
#define NULL ((void *) 0)
#endif
#ifndef TRUE /* Boolean true */
#define TRUE (1)
#endif
#ifndef FALSE /* Boolean false */
#define FALSE (0)
#endif
/*
** Check Sizes
*/
CompileTimeAssert(sizeof(uint8)==1, TypeUint8WrongSize);
CompileTimeAssert(sizeof(uint16)==2, TypeUint16WrongSize);
CompileTimeAssert(sizeof(uint32)==4, TypeUint32WrongSize);
CompileTimeAssert(sizeof(uint64)==8, TypeUint64WrongSize);
CompileTimeAssert(sizeof(int8)==1, Typeint8WrongSize);
CompileTimeAssert(sizeof(int16)==2, Typeint16WrongSize);
CompileTimeAssert(sizeof(int32)==4, Typeint32WrongSize);
CompileTimeAssert(sizeof(int64)==8, Typeint64WrongSize);
CompileTimeAssert(sizeof(cpuaddr) >= sizeof(void *), TypePtrWrongSize);
/*
* TEMPORARY COMPATIBILITY MACRO
*
* Any code that depends on this macro should be fixed so as to not need it.
* The value for this had been set by the BSP makefiles but this is not reliable,
* especially on processors that support both big- and little- endian modes e.g.
* ARM and MIPS.
*
* This is deprecated and only here to bridge the gap until code that depends
* on this can be fixed. Do not write any new code that uses this macro.
*
* If using an older makefile that defines one of the BIT_ORDER macros already,
* then this entire section is skipped and the macro is used as-is.
*/
#if !defined(SOFTWARE_BIG_BIT_ORDER) && !defined(SOFTWARE_LITTLE_BIT_ORDER)
#if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN || \
defined(__BIG_ENDIAN__) || \
defined(__ARMEB__) || \
defined(__THUMBEB__) || \
defined(__AARCH64EB__) || \
defined(_MIBSEB) || defined(__MIBSEB) || defined(__MIBSEB__)
/* It is a big-endian target architecture */
#define SOFTWARE_BIG_BIT_ORDER
#elif defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN || \
defined(__LITTLE_ENDIAN__) || \
defined(__ARMEL__) || \
defined(__THUMBEL__) || \
defined(__AARCH64EL__) || \
defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__)
/* It is a little-endian target architecture */
#define SOFTWARE_LITTLE_BIT_ORDER
#endif
#endif /* !defined(SOFTWARE_BIG_BIT_ORDER) && !defined(SOFTWARE_LITTLE_BIT_ORDER) */
#ifdef __cplusplus
}
#endif
#endif /* _common_types_ */
I tried checking if I have stdint.h and stddef.h and it turned out yes but I don't know why HAVE_STDINT isn't defined anywhere. Also, there is no case that checks for aarch64 which is my machine, so I changed
#if defined(_HAVE_STDINT_)
to
#if defined(_HAVE_STDINT_) || defined(__arch64__)
I tried compiling and it compiled most of the tools but then I got this error:
Source file 'to_config.o' contains objects of class type 'ELFCLASS64 (2)' which is unsupported by this utility
I'm guessing this error is happening because I removed the -m32 flag for the elf2cfetbl tool.
Any help?
I am trying to understand, what would be the best way to define BYTE, WORD and DWORD macros, which are mentioned in answers of this question.
#define LOWORD(l) ((WORD)(l))
#define HIWORD(l) ((WORD)(((DWORD)(l) >> 16) & 0xFFFF))
#define LOBYTE(w) ((BYTE)(w))
#define HIBYTE(w) ((BYTE)(((WORD)(w) >> 8) & 0xFF))
Would it be correct to assume, that:
BYTE is macro defined as
#define BYTE __uint8_t
WORD is macro defined as
#define WORD __uint16_t
DWORD is macro defined as
#define DWORD __uint32_t
If yes, why cast to another macro instead of casting to __uint8_t, __uint16_t or __uint32_t? Is it written like that to increase clarity?
I also found another question which answers include typedef, with little bit more of research I've found answers to question about comparing #define and typedef. Would typedef be better to use in this case?
This is a portable solution:
#include <stdint.h>
typedef uint32_t DWORD; // DWORD = unsigned 32 bit value
typedef uint16_t WORD; // WORD = unsigned 16 bit value
typedef uint8_t BYTE; // BYTE = unsigned 8 bit value
You have it defined at: https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx, and that is already defined in Windows Data Type headers for WinAPI:
typedef unsigned short WORD;
typedef unsigned char BYTE;
typedef unsigned long DWORD;
and it is a type, and not a macro.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
The difference of int8_t, int_least8_t and int_fast8_t?
I'm a quite confused. I think... (correct me if I'm wrong)
u_int8_t = unsigned short ?
u_int16_t = unsigned int ?
u_int32_t = unsigned long ?
u_int64_t = unsigned long long ?
int8_t = short ?
int16_t = int ?
int32_t = long ?
int64_t = long long ?
Then what does int_fast8_t mean? int_fastN_t? int_least8_t?
These are all specified in the C99 standard (section 7.18).
The [u]intN_t types are generic types (in the ISO C standard) where N represents a bit width (8, 16, etc). 8-bit is not necessarily a short or char since shorts/ints/longs/etc are defined to have a minimum range (not bitwidth) and may not be two's complement.
These newer types are two's complement regardless of the encoding of the more common types, which may be ones' complement or sign/magnitude ( see Representation of negative numbers in C? and Why is SCHAR_MIN defined as -127 in C99?).
fast and least are exactly what they sound like, fast-minimum-width types and types of at least a given width.
The standard also details which type are required and which are optional.
I writing where int is of 16-bit:
u_int8_t = unsigned char
u_int16_t = unsigned int
u_int32_t = unsigned long int
u_int64_t = unsigned long long int
int8_t = char
int16_t = int
int32_t = long int
int64_t = long long int
Q: "Then what does int_fast8_t mean? int_fastN_t? int_least8_t?"
As dan04 states in his answer here:
Suppose you have a C compiler for a 36-bit system, with char = 9
bits, short = 18 bits, int = 36 bits, and long = 72 bits. Then
int8_t does not exist, because there is no way to satisfy the constraint of having exactly 8 value bits with no padding.
int_least8_t is a typedef of char. NOT of short or int, because the standard requires the smallest type with at least 8
bits.
int_fast8_t can be anything. It's likely to be a typedef of int if the "native" size is considered to be "fast".
If you are in Linux most these are defined in /usr/include/linux/coda.h. e.g.
#ifndef __BIT_TYPES_DEFINED__
#define __BIT_TYPES_DEFINED__
typedef signed char int8_t;
typedef unsigned char u_int8_t;
typedef short int16_t;
typedef unsigned short u_int16_t;
typedef int int32_t;
typedef unsigned int u_int32_t;
#endif
And
#if defined(DJGPP) || defined(__CYGWIN32__)
#ifdef KERNEL
typedef unsigned long u_long;
typedef unsigned int u_int;
typedef unsigned short u_short;
typedef u_long ino_t;
typedef u_long dev_t;
typedef void * caddr_t;
#ifdef DOS
typedef unsigned __int64 u_quad_t;
#else
typedef unsigned long long u_quad_t;
#endif
It is my first experience with cygwin gcc, before that I used it on linux.
I faced a problem solution for which I failed to find in net.
I want to compile C source file and have included this source
// Value type defenitions
// --- chars --- //
typedef unsigned char UChar;
typedef char Char;
// --- short int --- //
typedef unsigned short UShort;
typedef short Short;
// --- int --- //
typedef unsigned int UInt;
typedef int Int;
// --- long int --- //
typedef long Long; // 32 bits length
typedef unsigned long ULong; // unsigned 32 bits length
// --- long long int --- //
typedef unsigned long long UBig; // 64-bit length unsigned
typedef long long Big; // 64-bit length
// --- decimals --- //
typedef float Float;
typedef double Double;
typedef long double Triple; // 80-bit length. Actual properties unspecified.
and have got this error
Include/null.h:6: error: redefinition of typedef 'UChar'
Include/null.h:6: error: previous declaration of 'UChar' was here
Include/null.h:7: error: redefinition of typedef 'Char'
Include/null.h:7: error: previous declaration of 'Char' was here
Include/null.h:9: error: redefinition of typedef 'UShort'
Include/null.h:9: error: previous declaration of 'UShort' was here
and so on...
Thank you for help!
Looks like you have included the same header, where you have typedef'edthese, more than once. Use include guards to avoid multiple inclusion.
Why I'm asking this is because following happens:
Defined in header:
typedef struct PID
{
// PID parameters
uint16_t Kp; // pGain
uint16_t Ki; // iGain
uint16_t Kd; // dGain
// PID calculations OLD ONES WHERE STATICS
int24_t pTerm;
int32_t iTerm;
int32_t dTerm;
int32_t PID;
// Extra variabels
int16_t CurrentError;
// PID Time
uint16_t tick;
}_PIDObject;
In C source:
static int16_t PIDUpdate(int16_t target, int16_t feedback)
{
_PIDObject PID2_t;
PID2_t.Kp = pGain2; // Has the value of 2000
PID2_t.CurrentError = target - feedback; // Has the value of 57
PID2_t.pTerm = PID2_t.Kp * PID2_t.CurrentError; // Should count this to (57x2000) = 114000
What happens when I debug is that it don't. The largest value I can define (kind of) in pGain2 is 1140. 1140x57 gives 64980.
Somehow it feels like the program thinks PID2_t.pTerm is a uint16_t. But it's not; it's declared bigger in the struct.
Has PID2_t.pTerm somehow got the value uint16_t from the first declared variables in the struct or
is it something wrong with the calculations, I have a uint16_t times a int16_t? This won't happen if I declare them outside a struct.
Also, here is my int def (have never been a problem before:
#ifdef __18CXX
typedef signed char int8_t; // -128 -> 127 // Char & Signed Char
typedef unsigned char uint8_t; // 0 -> 255 // Unsigned Char
typedef signed short int int16_t; // -32768 -> 32767 // Int
typedef unsigned short int uint16_t; // 0 -> 65535 // Unsigned Int
typedef signed short long int int24_t; // -8388608 -> 8388607 // Short Long
typedef unsigned short long int uint24_t; // 0 -> 16777215 // Unsigned Short Long
typedef signed long int int32_t; // -2147483648 -> 2147483647 // Long
typedef unsigned long int uint32_t; // 0 -> 4294967295 // Unsigned Long
#else
# include <stdint.h>
#endif
Try
PID2_t.pTerm = ((int24_t) PID2_t.Kp) * ((int24_t)PID2_t.CurrentError);
Joachim's comment explains why this works. The compiler isn't promoting the multiplicands to int24_t before multiplying, so there's an overflow. If we manually promote using casts, there is no overflow.
My system doesn't have an int24_t, so as some comments have said, where is that coming from?
After Joachim's comment, I wrote up a short test:
#include <stdint.h>
#include <stdio.h>
int main() {
uint16_t a = 2000, b = 57;
uint16_t c = a * b;
printf("%x\n%x\n", a*b, c);
}
Output:
1bd50
bd50
So you're getting the first 2 bytes, consistent with an int16_t. So the problem does seem to be that your int24_t is not defined correctly.
As others have pointed out, your int24_t appears to be defined to be 16 bits. Beside the fact that it's too small, you should be careful with this type definition in general. stdint.h specifies the uint_Nt types to be exactly N bits. So assuming your processor and compiler don't actually have a 24-bit data type, you're breaking with the standard convention. If you're going to end up defining it as a 32-bit type, it'd be more reasonable to name it uint_least24_t, which follows the pattern of integer types that are at least big enough to hold N bits. The distinction is important because somebody might expect uint24_t to rollover above 16777215.