Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
example_peek.cpp
00001 #include "MicroBit.h" 00002 #include "MicroBitPin.h" 00003 #include "cppNorm.h" 00004 #include "common.h" 00005 00006 00007 /** 00008 * conclusion: items incl char and char[] are on stack 4 byte alligned (0,4,8,c) 00009 * on global data char isn't aligned. 00010 * int8_t[] seems to 2 aligned, but it would demand a clean global date area to find out 00011 * variables are not source code ordered! 00012 */ 00013 void typeSizeAndAlignment() { 00014 #define outputscreeen1 00015 #ifdef outputscreeen1 00016 double d1; 00017 int8_t int8[3]; 00018 int16_t int16; 00019 int32_t int32; 00020 int32_t i32; 00021 // ADRESS bytes in decimal 00022 // 00023 void *addresses[] = { 00024 int8 // b8 4 00025 ,&int8[3] // bb 3 00026 ,&int16 // bc 4 00027 ,&d1 // c0 8 00028 ,&int32 // c8 4 00029 ,&i32}; // cc 00030 char names[][8] = { 00031 "int8" 00032 ,"int8[3]" 00033 ,"int16" 00034 ,"d1" 00035 ,"int32" 00036 ,"i32" 00037 }; 00038 #else 00039 int i; 00040 float f; 00041 char ch1; 00042 char chre[9]; 00043 char chr3[3]; 00044 char chr4[4]; 00045 char chr2[2]; 00046 // ADRESS bytes(decimal) 00047 void *addresses[] = { 00048 chre // ac 12 00049 ,&i // b8 4 00050 ,&f // bc 4 00051 ,&ch1 // c0 4 00052 ,chr3 // c4 4 00053 ,chr4 // c8 4 00054 ,chr2 }; // cc 00055 char names[][8] = { 00056 "chre[9]" 00057 ,"i" 00058 ,"f" 00059 ,"ch1" 00060 ,"chr3[3]" 00061 ,"chr4[4]" 00062 ,"chr2[2]" 00063 }; 00064 00065 #endif 00066 00067 for (int i=0; i < sizeof(addresses)/4; i++) 00068 oled.printf("%-8s %p\n",names[i],addresses[i]); 00069 } 00070 struct { 00071 const static int isConstStatic=0; 00072 } HasConstStatic; 00073 00074 int csint; 00075 00076 void isGlobalConstStaticFlashed() { 00077 static int k=2; 00078 oled.printf("const static \naddr:%p\n",&csint); 00079 oled.printf("addr:%p\n",&HasConstStatic.isConstStatic); 00080 oled.printf("addr:%p\n",&k); 00081 oled.printf("%d",csint); 00082 } 00083 00084 void example_peek() { 00085 oled.init(); 00086 //typeSizeAndAlignment(); 00087 isGlobalConstStaticFlashed(); 00088 release_fiber(); 00089 } 00090 00091
Generated on Mon Jul 18 2022 21:57:34 by
1.7.2