Cranes Varsity Blog

Volatile is a qualifier that is applied to a variable when it is declared. It tells the compiler that the value of the variable may change any time. The implications of this are quite serious.

It is required when you experience the following in C/C++ code:

  1. Code that works fine-until you turn optimization on
  2. Code that works fine-as long as interrupts are disabled
  3. Faulty hardware drivers
  4. Tasks that work fine in isolation-yet crash when another task is enabled

Syntax:

For declaration of volatile variable, make use of volatile keyword before or after the datatype. For instance

int volatile num;

volatile int num;

Pointer can also be declared as volatile:

int volatile *ptr;

volatile int *ptr;

Hence, if you apply volatile to struct or union, the entire contents of the struct/union are volatile. Perhaps, if we don’t want this behavior, the apply the volatile qualifier to the individual members of the struct/union.

When should be volatile used?

A variable should be declared volatile whenever its value could change unexpectedly. For instance

  1. Memory mapped peripheral register
  2. Global variables modified by an interrupt service routine
  3. Global variables within a multi-threaded application 

Conclusion

Volatile keyword is used to change the variable whose values can be changed and it doesn’t have any constant value. The volatile qualifier is intended to prevent the compiler from applying any optimizations on objects that can change in ways that cannot be determined by the compiler. volatile qualifier are mainly used for global variables.

In a program the most significant function is the main() function. It is defined with a return type of int and without arguments

 int main()

  {

    /* ... */

  }

Command-line arguments are typically the arguments given to the main function.It includes two arguments the first argument is the number of command line arguments and second is list of command-line arguments.

 int main(int argc, char *argv[])

  {

          /* ... */                 

  }

argc (argumented Count)-> is of type integer and includes the count of number of arguments including the program name.Therefore if we pass a single argument,the count of argc will be 2 (one for argument and one for program name).The value of the count cannot be negative.

argv (argumented Vector)->is array of character pointers listing all the arguments.

Properties of Command Line Arguments:

These arguments passed to main() function.

  • These are parameters/arguments supplied to the program when it is   

invoked.

  • argv[argc] is a NULL pointer.
  • argv[0] holds the name of the program.
  • argv[1] points to the first command line
  • argument and argv[n] points last argument.

Note : Command line arguments  are separated by a space, but if argument itself is  a space then we should  pass such arguments by putting them inside double quotes ""or single quotes ''.

Firmware

Dual booting is not just a matter of software. Or, it is, but it involves changing your firmware, which among other things tells your machine how to begin the boot process. Here are some firmware-related issues to keep in mind.

UEFI vs. BIOS

Before attempting to install, make sure your firmware configuration is optimal. Most computers sold today have a new type of firmware known as Unified Extensible Firmware Interface (UEFI), which has pretty much replaced the other firmware known as Basic Input Output System (BIOS), which is often included through the mode many providers call Legacy Boot.

Secure Boot

One other important setting is Secure Boot. This feature detects whether the boot path has been tampered with, and stops unapproved operating systems from booting. For now, I disabled this option to ensure that I could install Fedora Linux. According to the Fedora Project Wiki Features/Secure Boot Fedora Linux will work with it enabled. This may be different for other Linux distributions.

In short, if you find that you cannot install your Linux OS with this setting active, disable Secure Boot and try again.

Partitioning the boot drive

If you choose to dual boot and have both operating systems on the same drive, you have to break it into partitions. Even if you dual boot using two different drives, most Linux installations are best broken into a few basic partitions for a variety of reasons. Here are some options to consider.

GPT vs MBR

If you decide to manually partition your boot drive in advance, I recommend using the GUID Partition Table (GPT) rather than the older Master Boot Record (MBR). Among the reasons for this change, there are two specific limitations of MBR that GPT doesn’t have:

  • MBR can hold up to 15 partitions, while GPT can hold up to 128.
  • MBR only supports up to 2 terabytes, while GPT uses 64-bit addresses which allows it to support disks up to 8 million terabytes.

The EFI system partition

If you are doing a fresh installation or using a new drive, there are probably no partitions to begin with. In this case, the OS installer will create the first one, which is the EFI System Partition (ESP). If you choose to manually partition your drive using a tool such as gdisk, you will need to create this partition with several parameters. Based on the existing ESP, I set the size to around 500MB and assigned it the ef00 (EFI System) partition type. The UEFI specification requires the format to be FAT32/msdos, most likely because it is supportable by a wide range of operating systems.

Operating System Installation

Once you accomplish the first two tasks, you can install your operating systems. While I focus on Windows 10 and Fedora Linux here, the process is fairly similar when installing other combinations as well.

Windows 10

I started the Windows 10 installation and created a 20 Gigabyte Windows partition. Since I had previously installed Linux on my laptop, the drive had an ESP, which I chose to keep. I deleted all existing Linux and swap partitions to start fresh, and then started my Windows installation. The Windows installer automatically created another small partition—16 Megabytes—called the Microsoft Reserved Partition (MSR). Roughly 400 Gigabytes of un-allocated space remained on the 512GB boot drive once this was finished.

I then proceeded with and completed the Windows 10 installation process. I then rebooted into Windows to make sure it was working, created my user account, set up wi-fi, and completed other tasks that need to be done on a first-time OS installation.

Fedora Linux

I next moved to install Linux. I started the process, and when it reached the disk configuration steps, I made sure not to change the Windows NTFS and MSR partitions. I also did not change the EPS, but I did set its mount point to /boot/efi. I then created the usual ext4 formatted partitions, / (root), /boot, and /home. The last partition I created was Linux swap.

As with Windows, I continued and completed the Linux installation, and then rebooted. To my delight, at boot time the GRand Unified Boot Loader (GRUB) menu provided the choice to select either Windows or Linux, which meant I did not have to do any additional configuration. I selected Linux and completed the usual steps such as creating my user account.

            A structure is a user defined data types, it is used to group a different type into a single type. It allocates contiguous memory locations, we can access the structure elements through structure variable along with dot operator or arrow operator depends upon the structure variable, if structure variable is pointer will use arrow operator else will use dot operator, memory will be arranged by structure padding

Declaration :  struct structure name

                        {         

                                    Structure members;

                                    ......

                                    ......

                        }s;

ex:

            struct dbase

            {

                        char a;

                        short b;

                        int c;

                        float d;                       

            }s;

Structure Initialization:

  1. if we initialize a structure, need to create structure variable along with that will give value also

            Examples :

            struct dbase

            {

                        char ch;

                        short n1;

                        int n2;

                        float pi;

            }s = {'z', 12, 512, 3.14};

            In above example, struct is a keyword, dbase is a structure name/tag name it allocates 12 bytes contiguous manner. We can access the structure members along with structure variable with dot operator(ex. s.ch,s.n1,..)      

Structure Declaration:

1.If we declare a structure outside the main, it allocates space in data segment, if it inside the main it allocates in stack memory.

Examples:

            struct dbase

            {

                        char ch;

                        short n1;

                        int n2;

                        float pi;

            }s ;

int main()

{          s.ch = 'z';

            s.n1 = 12;

            s.n2 = 34;

            s.pi = 3.14;

            printf(“%c %hd %d %f\n”,s.ch,s.n1,s.n2,s.pi);

}

What is a structure pointer?
Like primitive types, we can have pointer to a structure. If we have a pointer to structure, members are accessed using arrow ( -> ) operator.

#include<stdio.h>

struct dbase

{

            int x,y;

};

int main() {

            struct dbase p1 ={1,2};

            struct dbase *p2 = &p1;

            printf(“%d %d”,p1->x,p2->x);

}

A tilt sensor used for measuring the tilt in multiple axes of a reference plane. The tilting position gives a measure  with reference to gravity and are used in number of applications. They allows the easy detection of orientation or inclination. Similar to mercury switches, they may also be known as tilt switches or rolling ball sensors.

These instruments have become gradually more popular and are being adapted for increasing numbers of high end applications. For example, the sensor provides valuable information about both the vertical and horizontal inclination of an airplane, which helps the pilot to understand how to tackle obstacles during the flight. By knowing the current orientation of the plane, and the angle at which the plane is inclined to the earth's surface, stunt pilots, i.e. the Red Arrows, can put on a fascinating air show. Tilt sensors are an essential decision-making tool for the pilots.

Operating Principle:

A tilt sensor has a metallic ball that is designed to move the two pins of the instrument from the 'on' to the 'off' position, and vice versa, if the sensor reaches a pre-determined angle. Tilt sensors are the environment-friendly version of a mercury-switch.

The key benefits of tilt sensors include:

  • Compact and simple to use
  • High resolution and accuracy
  • Very cost-effective
  • Low power consumption
  • Can be read by industry standard data loggers

 key applications of tilt sensors:

  • Monitoring the angle at which a mobile phone or tablet is held for the auto-rotate function 
  • Detecting the position of hand-held game systems and in game controllers 
  • Indicating the roll of boats, vehicles and aircraft 
  • Measuring the angle at which a satellite antenna 'looks' toward a satellite 
  • Estimating the height of a tree or building 
  • Measuring the steepness of a ski slope 
  • To provide a warning system for the surface tilt angle of cryogenic liquids during transportation
  • To monitor laser levels and seismic activity