Some people consider language only as a tool, and using any language is the same. Some are fanatical about one language, and consider other languages as bad. In my opinion the truth is between them. In many cases, using any language is the same, but in certain cases certain languages are better than other languages.
Programming embedded systems in C will be easier than using Pascal for example. The use of C in embedded systems also saves memory, which will save equipment production costs. To be able to use a language properly, we need to know why certain features exist in a language, and when we should use it.

1. STRING BASIC DATA MODEL

String is actually the use of group char data types.
The string data type is an array of char data types.

Declaration of String Variables:
Because String is an array of char, the declaration is the same as declaring an array of char, which is:
                                    Char variable_name [character_count]

Example:
char address [40] -> declaration of address variables with string data types.
Address Variable Value consists of several characters up to 40 characters (0 to 39)

v Initializing String Variables:
String variables can be initialized in the following way:
                 Char name [10] = “liejouly”;
name in memory after initialization:
The character (” “) in name [10] is a null character that marks the end of a string.

Loading...

2. STRUCTURE OF ENUMARIZATION DATA TYPE
The enumeration type is a type in which values that might be mentioned one by one by the programmer. For example the type of day consisting of Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. Many programming languages have enumeration types, for example C, Pascal, C #, Java 5 and above, Ada, and Visual Basic.

In implementation, enumeration is usually implemented as an integer data type. You can just make the day type an integer number with constants (Monday = 1, Tuesday = 2, etc.), but using enumeration can help make the program clearer.


Enumarisation type is a data type whose value is limited to predefined values. This type is used to form data types that are definite in nature. For example the name of the day, gender and so on. General form:
enum nama_tipe (value1, value2, value3, …)
  Example:
  enum sex types (male, female);
enum days (sunday, monday, tuesday, wednesday, thursday, friday, saturday);

3. DATA UNION TYPE STRUCTURE

Just like structs, union is also a data type that is raised, where members use the same memory storage space together, different from the structure in which each variable occupies a different memory location.
The number of bytes used to store a union is at least enough to store the largest data handled. Union types are generally used to handle one, two, or three variables with similar types.

Use:

saves system memory usage. also useful for low level programming.

Union allows one and the same piece of memory to be accessed as different data types, because all actually have the same location in memory. modification of one element will affect all values. One use of trade unions might be to unite elementary types with arrays or structures of smaller elements.
v Declaration of use of Union:

union_name {
   member_type1 member_name1;
   member_type2 member_name2;
   member_type3 member_name3;
} Object_names;

All elements of the union declaration occupy the same physical space in memory. Its size is one of the biggest elements of a declaration. As an example:

123 union mytypes_t {
   char c;
   int i;
   yuli b;
   } Mytypes;

Defines three elements:


123 mytypes.c
mytypes.i
mytypes.b

4. STRUCTURE OF FIELD DATA BIT TYPE

A Bit Field data type is an idiom commonly used in computer programming to store multiple logical values ​​as a short series of bits where each single bit can be handled separately. A Bit Field is most often used to represent integral types of known, bit-fixed widths. A Bit Field is distinguished from an array of bits in that the latter is used to store a large set of bits indexed by integers. Bit Field, on the other hand, is usually appropriate in machine words, and bit denotation is independent of numerical indices.

Even though languages ​​like C or C ++ have built-in support for bit fields, it can still be implemented manually. The bitwise AND, OR, and NOT operators are used in combination to set / unset flags, or to determine whether certain flags are set / set, respectively. In order to do the latter, bitwise is needed with all bits deactivated except for those that are supposed to be tested. If the value of the bit set by to test the bit mask results in the same mask bit, then all the bits are activated on the original bit set.

Example:
#define KEY_UP (1 << 0)
#define KEY_RIGHT (1 << 1)
#define KEY_DOWN (1 << 2)
#define KEY_LEFT (1 << 3)
#define KEY_BUTTON1 (1 << 4)
#define KEY_BUTTON2 (1 << 5)

int gameControllerStatus = 0;

void keyPressed (int key) {
     gameControllerStatus | = key;
}
void keyReleased (int key) {
    gameControllerStatus & = ~ key;
}
 int isPressed (int key) {
    return gameControllerStatus & key;
}

5. TYPEDEF DATA TYPE STRUCTURE

Typedef is a keyword in the C and C ++ programming languages. The purpose of typedefs is to assign alternative names to existing types,
In the C convention (as in the standard C library),
For example:


123 Char C typedef;
word int typedef unsigned;
typedef char * PChar;
Char typedef field [50];


In this case we have defined four data types: C, word, PChar and fields as char, unsigned int, char * and char [50] respectively, that we can perfectly use in later declarations as any other true type:

123C mychar, anotherchar, * ptc1;

myword words;

PCHAR PTC2;

column name;

Typedef does not create various types. It only creates synonyms of the type that exists. That means that the type of myword can be considered either word or int unsigned, because they are actually of the same type. Typedef can be useful to determine the types that are often used in programs. It is also useful to determine the type when possible we will need if the type you want to use has a name that is too long or confusing.

0/5 (0 Reviews)

LEAVE A REPLY

Please enter your comment!
Please enter your name here