Skip to content

Instantly share code, notes, and snippets.

Created January 3, 2013 21:55
Show Gist options
  • Select an option

  • Save anonymous/4447740 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/4447740 to your computer and use it in GitHub Desktop.
Code to test static_cast
#include <stdio.h>
#ifdef _WIN32
#include <windows.h> // for timeGetTime()
#else
#include <unistd.h> // for usleep
#include <time.h> // for timer
#endif
#ifndef _WIN32
static int timeGetTime()
{
timespec t;
clock_gettime(CLOCK_MONOTONIC, &t);
return S32(((U64(t.tv_nsec) * 4295) >> 32)) + S32(U32(t.tv_sec) * 1000);
}
#endif
struct aa1{int a1;};
struct aa2{int a2;};
struct aa3{int a3;};
struct aacombined : public aa1, public aa2, public aa3 {int aaa;};
void print_a(aacombined *c)
{
printf("%p\n", c);
printf("%p %p\n", (aa1*)c, static_cast<aa1*>(c));
printf("%p %p\n", (aa2*)c, static_cast<aa2*>(c));
printf("%p %p\n", (aa3*)c, static_cast<aa3*>(c));
}
//int _tmain(int argc, _TCHAR* argv[])
int main(int argc, char **argv)
{
int a = 0;
//for(int i=0; i < 100000; i++)
// a += isVisibleOnCmdrsMapWithSensorType2(U8(i) & 127) ? 1 : 0;
aacombined cc;
print_a(&cc);
print_a(NULL);
#ifdef _WIN32
Sleep(10000);
#endif
return 0;
}
@eykamp
Copy link

eykamp commented Jan 3, 2013

This looks like a good test of static_casting nulls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment