#define SOMETHING of type int16_t

How to define different types of ints?

I have the following

struct movCommand
{
    uint8_t type;
    uint8_t order;
    int16_t height;
    uint16_t distance;
    int16_t yaw;
};

and you must define them according to the types that they are.

What is the correct syntax for #definewhen choosing a type to define?

EDIT:

It seems my question was misunderstood.

I want to do this #define LANDING_COMMAND "2" But I want to set the type of touchdown command because it must be int16_t

+3
source share
7 answers

You do not use for this #define. You#include <stdint.h>

+4
source

, #define, typedef, <stdint.h> ( , , C99). , , . typedefs :

typedef unsigned char uint8_t;
typedef signed char int8_t;
typedef unsigned short uint16_t;
typedef signed short int16_t;
typedef unsigned int uint32_t;
typedef int int32_t;
//... etc., etc.

typedef, 64- ..

+2

C99, typedef <stdint.h> <inttypes.h> ( <inttypes.h> , <stdint.h> - , C99).

( ), , , .

a typedef #define.

+2

, #define , .

#define LANDING_COMMAND "2";

LANDING_COMMAND "2"; . , , .

-, C, . C, , ;. , , , , , func(LANDING_COMMAND);.

-, "2" char *, int16_t . 2 .

, int16_t, cast (((int16_t)2)) , INT16_C(2), , ( ) int16_t. , . INT16_C(2) , ( ) int_least16_t, , . stdint.h [u]int_leastN_t [u]intmax_t, [u]intN_t [u]int_fastN_t. .

+1

include stdint.h 8, 16, 32 64 .

http://en.wikipedia.org/wiki/Stdint.h

0
source

You cannot do what you describe. Other answers point to workarounds. As for your specific question, from the MSDN website :

Expressions must be of integral type and may include only integer constants, symbolic constants, and a specific operator.

An expression cannot use sizeof or a cast operator.

0
source

#definehas no type. This is exactly the same as find / replace in your editor. You can do

#define LANDING_COMMAND 2
...
my_movCommand.yaw = LANDING_COMMAND;

The compiler will do the right type conversions for you, but if you insist on a type int16_t, then

#define LANDING_COMMAND ((int16_t)2)
0
source

All Articles