Conditional Compilation In C: #ifndef #else #endif

In this video tutorial lets learn about preprocessor command or directives like #ifndef, #else and #endif. These directives are used for conditional compilation. #ifndef works completely opposite to #ifdef

Related Read:
Conditional Compilation In C: #ifdef #else #endif

How Does #ifndef Work?

The block of code between #ifndef and #endif works only if the macro name is NOT defined. If the macro name is defined, the compiler will skip the entire block of code inside #ifndef from compiling.

When To Use #ifndef

We’ve explained this in detail for video tutorial: Conditional Compilation In C: #ifdef #else #endif It holds good for this video tutorial too.

Video Tutorial: Conditional Compilation In C: #ifndef #else #endif


[youtube https://www.youtube.com/watch?v=Y7UEY7Cxz7Y]

YouTube Link: https://www.youtube.com/watch?v=Y7UEY7Cxz7Y [Watch the Video In Full Screen.]

Source Code: Conditional Compilation In C: #ifndef #else #endif

#include<stdio.h>

#define iOS

int main()
{
    #ifndef iOS
        printf("I Love Apple Devices\n");
    #else
        printf("Code for Non Apple Devices\n");
    #endif // iOS

    return 0;
}

Output:
Code for Non Apple Devices

#include<stdio.h>


int main()
{
    #ifndef iOS
        printf("I Love Apple Devices\n");
    #else
        printf("Code for Non Apple Devices\n");
    #endif // iOS

    return 0;
}

Output:
I Love Apple Devices

In above programs, if iOS macro name is defined, then the set of code present inside #else block gets compiled and executed. If macro name iOS is not defined, then the code inside #ifndef block gets compiled and executed.

Note:

1. Using #else is optional. You can just use #ifndef and #endif.

2. Working of #ifndef is opposite to that of #ifdef.

3. This is similar to if else condition, but here the block of code which do not match the criteria doesn’t even get compiled. It’s treated like regular comments.

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

Conditional Compilation In C: #ifdef #else #endif

In this video tutorial lets learn about preprocessor command or directives like #ifdef, #else and #endif. These directives are used for conditional compilation.

How Does #ifdef Work?

The block of code between #ifdef and #endif works only if the macro name is defined orelse the compiler will skip the entire block of code from compiling.

When To Use #ifdef

1. When we want the compiler to skip certain part of the source code: For this we could even use multi-line comment, but if we already had multi-line comments in the code, we can’t enclose the source code and multi-line comments with another multi-line comment. Nesting of multi-line comments are not allowed in C programming language. So instead of commenting the code we could make use of #ifdef directive.

2. To write portable code: For example, we could write code both for iOS and non-iOS devices. Using #ifdef we could check the device OS and based on that deliver specific set of codes. For this we can use #ifdef

Video Tutorial: Conditional Compilation In C: #ifdef #else #endif


[youtube https://www.youtube.com/watch?v=J0nWQRqb3Fc]

YouTube Link: https://www.youtube.com/watch?v=J0nWQRqb3Fc [Watch the Video In Full Screen.]

Source Code: Conditional Compilation In C: #ifdef #else #endif

#include<stdio.h>

#define iOS

int main()
{

    #ifdef iOS
        printf("This is iOS Code\n");
    #else
        printf("This is code for Android Devices\n");
    #endif // iOS

    return 0;
}

Output:
This is iOS Code

#include<stdio.h>

int main()
{

    #ifdef iOS
        printf("This is iOS Code\n");
    #else
        printf("This is code for Android Devices\n");
    #endif // iOS

    return 0;
}

Output:
This is code for Android Devices

In above programs, if iOS macro name is defined, then the set of code present inside #ifdef block gets compiled and executed. If macro name iOS is not defined, then the code inside #else block gets compiled and executed.

#include<stdio.h>
#define iOS

int main()
{

    #ifdef iOS
        printf("This is iOS Code\n");
    #endif // iOS

    printf("This is code for all non iOS Devices\n");

    return 0;
}

Output:
This is iOS Code
This is code for all non iOS Devices

#include<stdio.h>

int main()
{

    #ifdef iOS
        printf("This is iOS Code\n");
    #endif // iOS

    printf("This is code for all non iOS Devices\n");

    return 0;
}

Output:
This is code for all non iOS Devices

Note: using #else is optional. You can just use #ifdef and #endif.

This is similar to if else condition, but here the block of code which do not match the criteria doesn’t even get compiled. It’s treated like regular comments.

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

Details Arrow: Ionic 2

Today lets see how we can add details arrow or the right arrow icon to our list items in Ionic 2.

ion-item-right-arrow-icon

Ionic uses modes to customize the look of components. Each platform has a default mode, but this can be overridden. For example, an app being viewed on an Android platform will use the md (Material Design) mode. The < ion -app > tag(in index.html) will have class=”md” added to it by default and all of the components will use Material Design styles:

index.html

< ion-app class="md">

Default Modes used on different platforms
ios devices – ios mode.
android devices – md(Material Design) mode.
windows devices – wp mode.

ion-list item Right Arrow Icon: Ionic 2


[youtube https://www.youtube.com/watch?v=gCXS6gRuyvk]

YouTube Link: https://www.youtube.com/watch?v=gCXS6gRuyvk [Watch the Video In Full Screen.]



In ios mode, buttons and anchor elements with ion-item attribute will display right arrow icon by default. If you want to remove this right icon you should add detail-none attribute to your elements.

Note:
1. For removing right arrow icon use detail-none attribute on your elements.
2. To add right arrow icon use detail-push attribute on your elements.

If the arrow still doesn’t display, you need to overriding some variables inside src/theme/variables.scss file.

For iOS Mode: iOS devices

$item-ios-detail-push-show: true;

For md mode: android devices

$item-md-detail-push-show: true;

For wp mode: Windows Devices

$item-wp-detail-push-show: true;

Important:
If you are previewing or testing your ionic 2 application using Chrome browser on Windows machine, then set variable $item-wp-detail-push-show also to true or else simply set the one applicable to your target device.

src/pages/home/home.ts

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
 
@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  companies: any;
  constructor(public navCtrl: NavController) {
    this.companies = [
      {name: 'Microsoft', code: 1},
      {name: 'Apple', code: 2},
      {name: 'Google', code: 3},
      {name: 'Oracle', code: 4}
    ];
  }
}

src/pages/home/home.html

  < ion-list no-lines>
    < ion-item *ngFor="let company of companies" detail-push>
      {{company.name}}
    < /ion-item>
  < /ion-list>

For explanation of above code please watch: Basics of Page Component: Ionic 2 video tutorial.

Remove Lines From ion-list items
Add no-lines attribute to ion-list tag to remove the default linings from the list items displayed on the view.