Month: September 2020

Microsoft finds underwater datacenters are reliable, practical and use energy sustainably | Innovation Stories

Earlier this summer, marine specialists reeled up a shipping-container-size datacenter coated in algae, barnacles and sea anemones from the seafloor off Scotland’s Orkney Islands.The retrieval launched the final phase of a years-long effort that proved the concept of underwater datacenters is feasible, as well as logistically, environmentally and economically practical.

Source: Microsoft finds underwater datacenters are reliable, practical and use energy sustainably | Innovation Stories

C/C++ Tokens – GeeksforGeeks

In C/C++ tokens are the smallest element of a program. Tokens can be split into the following

1. Keywords
Predefined tokens in a programming language having fixed meaning.
e.g:- switch, case, int,return etc.

C++ has 31 additional keywords
few of the common ones used are
bool, class,static_cast,try, catch etc

2. Identifiers
Identifiers are used to name variables, labels etc. There are certain rules for the identifiers
a. They can start only with a letter or underscore(_).
b. They must contain only digits, letters and underscore.
c. They cannot contain white space.
d. maximum up to 31 characters long.
e. white space not allowed.

3. Constants
Constants refer to fixed values. e.g:- integer constants, floating point constants, character constants, octal or hexadecimal constants and string constants.
E.g:-
char *p=”Yogi”;
int age=43;

In the above examples “Yogi” and 43 are string and integer constants.

4. Strings
They are array of characters ended with null character(\0)

eg:- char test[20]=”Yogi”;

5. Symbols
Symbols have special meaning.
a. Brackets[]- used for array subscripts.
b. Paranthesis() – used for function calls and parameter passing.
c. Braces{} – Used for separating blocks of code. A variable defined inside the brace will have the scope within the brace.
d. comma, – separates statements and parameters.
e. asterisk * – Use to dereference a pointer.

There are other set of symbols also used and each has its own meaning.

6. Operators
Operators are symbols that are used to perform with operands to create a statement.
Based on the number of operands operator can act upon, operators can be classified as

a. Unary operator – i++, i–;
b. Binary operators – Arithmetic, relational, logical, assignment, conditional, bitwise
c. Ternary operator – ?:

Source: C/C++ Tokens – GeeksforGeeks

Line Splicing 

In C and C++ you can join the next line to the current line using Line spicing. Requires ‘\’ to be added at the end of the line.

 

Example code to demostrate line splicing.

[yogi@192 devel]$ cat linesplice.c
#include <stdio.h>

int main(int argc, char *argv[])
{
// test line splice
printf(“Hello\n”);
printf(“World\n”);

return 0;
}
[yogi@192 devel]$ gcc -o linesplice linesplice.c
[yogi@192 devel]$ ./linesplice
Hello
World
[yogi@192 devel]$ vi linesplice.c
[yogi@192 devel]$ cat linesplice.c
#include <stdio.h>

int main(int argc, char *argv[])
{
// test line splice \
printf(“Hello\n”);
printf(“World\n”);

return 0;
}
[yogi@192 devel]$ gcc -o linesplice linesplice.c
[yogi@192 devel]$ ./linesplice
World
[yogi@192 devel]$ vi linesplice.c
[yogi@192 devel]$ gcc -o linesplice linesplice.c
[yogi@192 devel]$ cat linesplice.c
#include <stdio.h>

int main(int argc, char *argv[])
{
// test line splice \
printf(“Hello\n”); \
printf(“World\n”);

return 0;
}
[yogi@192 devel]$ ./linesplice
[yogi@192 devel]$

 

Source: Line Splicing in C/C++ – GeeksforGeeks

Signals in C

Signals are one of the IPC mechanism used to communicate between 2 processes or between OS and a process. If a program hits a serious error, the OS may raise the respective signal for the process to be terminated after a core dump file is generated.

 

The common error signals are

SIGFPE:- some arithhmetic errors or floating point errors like divide by zero.

SIGILL:- Illegal instruction. Usually happens when an unknown instruction or an elevated privilege instructions is run. Common scenario is object file is corrupted or a stack overflow happens.

SIGSEGV:- Happens when a process access the physical memory which it doesn’t have access to. Common scenario is accessing a NULL pointer, stack or heap corruption.

SIGBUS:- Bus error. Invalid memory is accessed. In case of bus error the memory accessed itself is invalid. One scenario is issues with HW where the memory mapped address access fails to read the data from the hardware.

SIGABRT:- The signal is raised when the program calls abort() api. assert() in C++ uses internally abort().

SIGSYS:- The signal is raised when a process passes invalid arguments to a system call.

SIGTRAP:- This signal is raised in conjunction when a debugger is attached to the process. When the code hits a debug point the SIGTRAP can be raised.

Source: Program error signals – GeeksforGeeks

To be continued…