Demo for GetTypeName library, using all defined types.

Dependencies:   GetTypeName mbed

main.cpp

Committer:
frankvnk
Date:
2015-02-15
Revision:
0:51ba9e864352

File content as of revision 0:51ba9e864352:

#include "mbed.h"
#include "GetTypeName.h"

int main()
{
    char a = 65;
    uint8_t b = 20;
    signed char c = -30;
    int8_t d = -40;
    unsigned short e = 50;
    uint16_t f = 60;
    short g = -70;
    int16_t h = -80;
    unsigned int i = 90;
    uint32_t j = 100;
    int k = -110;
    int32_t l = -120;
    unsigned long long m = 130;
    uint64_t n = 140;
    long long o = -150;
    int64_t p = -160;
    float q = 1.7;
    double r = 1.8;
    bool s = 1;

    printf("Type name for <char> '%c' is %s\r\n", a, GetTypeName(a));
    printf("Type name for <uint8_t> %d is %s\r\n", b, GetTypeName(b));
    printf("Type name for <signed char> %d is %s\r\n", c, GetTypeName(c));
    printf("Type name for <int8_t> %d is %s\r\n", d, GetTypeName(d));
    printf("Type name for <unsigned short> %d is %s\r\n", e, GetTypeName(e));
    printf("Type name for <uint16_t> %d is %s\r\n", f, GetTypeName(f));
    printf("Type name for <short> %d is %s\r\n", g, GetTypeName(g));
    printf("Type name for <int16_t> %d is %s\r\n", h, GetTypeName(h));
    printf("Type name for <unsigned int> %d is %s\r\n", i, GetTypeName(i));
    printf("Type name for <uint32_t> %d is %s\r\n", j, GetTypeName(j));
    printf("Type name for <int> %d is %s\r\n", k, GetTypeName(k));
    printf("Type name for <int32_t> %d is %s\r\n", l, GetTypeName(l));
    printf("Type name for <unsigned long long> %lld is %s\r\n", m, GetTypeName(m));
    printf("Type name for <uint64_t> %lld is %s\r\n", n, GetTypeName(n));
    printf("Type name for <long long> %lld is %s\r\n", o, GetTypeName(o));
    printf("Type name for <int64_t> %lld is %s\r\n", p, GetTypeName(p));
    printf("Type name for <float> %f is %s\r\n", q, GetTypeName(q));
    printf("Type name for <double> %f is %s\r\n", r, GetTypeName(r));
    printf("Type name for <bool> %d is %s\r\n", s, GetTypeName(s));
    
    // Store GetTypeName in a variable
    const char *VarType;
    VarType = GetTypeName(a);
    printf("'%c' is of '%s' type\r\n", a, VarType);
    
    // Check whether GetTypeName is of 'char' type.
    // Note that strcmp returns 0 when both strings are equal.
    if(!strcmp(GetTypeName(a),"char")) printf("'%c' is of 'char' type\r\n", a);
}