void boo1()
{
  C* c = new C;
  A* a = c;
  foo1(c); // Okay, implicit cast to base class
  foo2(a); // Okay, implicit cast to const
  foo2(c); // Okay, implicit cast to base class and const
  foo3(c); // Okay, implicit case to base class
  foo4(a); // Okay, no cast
  foo4(c); // Error, can not cast from (C&*) to (A&*)!
}
int main(int argc, char *argv[])
{
	int x = 27;
	const int cx = x;
	const int& rx = x;

	// Case 1: The template parameter type is a Reference or a Pointer, but
	// not an Universal reference.

	// Even if T is not const, if the passed parameter is const it has to be
	// enforced upon the "foo" function to ensure the constness.

	foo1(x);     // T is int, param is int&
	foo1(cx);    // T is int, param is const int&
	foo1(rx);    // T is int, param is const int&

	// The T type in foo2 is const, so the constness has to be enforced for any
	// given parameter type.

	foo2(x);     // T is int, param is const int&
	foo2(cx);    // T is int, param is const int&
	foo2(rx);    // T is int, param is const int&

	// Case 2: The template parameter type is an Universal reference.

	// If the passed parameter is an lvalue, both T and param will be lvalue
	// references. Otherwise, the rules described in "Case 1" apply.

	foo3(x);     // T is int&, param is int&
	foo3(cx);    // T is const int&, param is const int&
	foo3(rx);    // T is const int&, param is const int&
	foo3(27);    // T is int, param is int&&

	// Case 3: The template parameter type is neither a Reference nor a Pointer.

	// We're passing by value: references, const and volatile will be ignored.

	foo4(x);     // T is int, param is int
	foo4(cx);    // T is int, param is int
	foo4(rx);    // T is int, param is int

	// Pointers and C-style arrays have the same logic as before when deducing
	// their types.

	// Oh, by the way, did you know that you can pass C arrays by reference? :P
	int numbers[] = { 1, 2, 3, 4, 5 };
	std::cout << arraySize(numbers) << std::endl;
}
int main(int argc, char* argv[]) {
    // helper routine that could help the code.
    int loops;
    if (argc <= 1) {
        printf ("usage: test utility for CSE221 project.\n");
        exit(0);
    }
    else {
        loops = atoi (argv[1]);
        if (loops <= 0) {
            printf ("Invalid arguments.\n");
            exit(0);
        }
    }

    // auxillary functions that help the test
    volatile int a[8] = {0, 1, 2, 3, 4, 5, 6, 7};
    tick ts, te; /* tick start, tick end */
    /* start the clock */
    ts = gettick();

    /* do something do something big do something extraordinary do something for the entire humanity */
    volatile int i;
    for (i = 0; i < loops; ++i) {
        foo4(a[0], a[1], a[2], a[3]);
    }
    
    /* end the clock */
    te = gettick();
    printf ("delta t = %llu\n", te-ts);
}
Exemple #4
0
int main(int argc, char *argv[])
{
    int a[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

    foo1(a);
#pragma omp taskwait
    if (a[0] != 3)
        abort();
    a[0] = 0;

    foo2(a);
#pragma omp taskwait
    if (a[0] != 3)
        abort();
    a[0] = 0;

    foo3(a);
#pragma omp taskwait
    if (a[3] != 13
            || a[4] != 48)
        abort();
    a[3] = 3;
    a[4] = 4;

    foo4(a);
#pragma omp taskwait
    if (a[3] != 13
            || a[4] != 48)
        abort();

    return 0;
}
Exemple #5
0
int main()
{
    foo1();
    foo2();
    foo3();
    foo4();
}
Exemple #6
0
int main() {
  printf("%d\n", foo1());
  printf("%d\n", 5*foo1() + foo1());
  printf("%s", foo2());
  printf("%s", foo3());
  if (foo4()) {
    printf("Yes\n");
  }
}
Exemple #7
0
TEST(about_arrays, passing_arrays)
{
  char a[] = "om";
  foo1(a);
  foo2(a);
  foo3(a);
  foo4(a);
  foo5(&a);
}
Exemple #8
0
int main()
{
    //foo();
    //foo2();     // warning: ‘foo2’ used but never defined
    //foo3();     // warning: ‘foo3’ used but never defined
    foo4();

    return 0;
}
Exemple #9
0
int main ()
{
  {A<1> (); A<2> (); ;}
  {A<3> (), A<4> (); ;}
  foo1();
  foo2().Foo (), A<9> ();
  foo3().Foo (), A<12> ();
  {A<13> a; a; ; }
  foo4();
  Check (0, 0, 0, "end");
}
Exemple #10
0
int main(int argc, char* argv[]) {
  switch(argc) {
    case 1: return foo1();
    case 2: return foo2();
    case 3: return foo3();
    case 4: return foo4();
    case 5: return foo5();
    case 6: return foo6();
    default: return -1;
  }
}
Exemple #11
0
void oink() {
  int $tainted y;
  // works
  {int x = foo(1);}
  {int x = foo2(1);}
  {int x = foo3(1);}
  {int x = foo4(1);}

  {int x = gronk(y);}
  {int x = gronk2(y);}
}
Exemple #12
0
int main ()
{
  if (foo1 (0x13) != 8)
    abort();

  if (foo2 (0x06) != 27)
    abort();

  if (foo3 (0x02) != 4)
    abort();

  if (foo4 (0x01) != 7)
    abort();

  if (foo5 (0x15) != 65)
    abort();

  if (foo6 (0x103) != 8)
    abort();

  if (foo7 (0x04) != 21)
    abort();

  if (foo8 (0x07) != 72)
    abort();

  if (foo9 (0x10000011L) != 0)
    abort();

  if (foo10 (0x1000105L) != 0)
    abort();

  if (foo11 (0x1000008L) != 39)
    abort();

  if (foo12 (0x1000004L) != 0)
    abort();

  if (foo13 (0x109LL) != 0)
    abort();

  if (foo14 (0x108LL) != 39)
    abort();

  if (foo15 (0x1000001LL) != 7)
    abort();

  if (foo16 (0x100000004LL) != 21)
    abort();

  return 0;
}
Exemple #13
0
int
main() {
	struct tiny	y = { 77 };
	struct small	s = { 63444 };
	struct smallish	sm = { 474723747443LL };
	struct medium	m = { "hellohellohello" };

	foo(1, y, 2);
	foo2(3, s, 4);
	foo3(5, sm, 6);
	foo4(7, m, 8);
	return 0;
}
Exemple #14
0
int
main (int argc, short *argv[])
{
  vector short fetched_value = foo ();
  if (fetched_value[0] != 0 || fetched_value[7] != 7)
    abort ();

  fetched_value = foo1 ();
  if (fetched_value[1] != 1 || fetched_value[6] != 6)
    abort ();

  fetched_value = foo2 ();
  if (fetched_value[2] != 2 || fetched_value[5] != 5)
    abort ();

  fetched_value = foo3 (&x);
  if (fetched_value[3] != 3 || fetched_value[4] != 4)
    abort ();

  struct bar a_struct;
  a_struct.a_vector = x;	/* Remove 2 redundant swaps.  */
  fetched_value = foo4 (&a_struct);
  if (fetched_value[4] != 4 || fetched_value[3] != 3)
    abort ();

  for (int i = 0; i < 8; i++)
    z[i] = 7 - i;

  baz (z);
  if (x[0] != 7 || x[7] != 0)
    abort ();

  vector short source = { 8, 7, 6, 5, 4, 3, 2, 1 };

  baz1 (source);
  if (x[3] != 5 || x[7] != 1)
    abort ();

  vector short dest;
  baz2 (&dest, source);
  if (dest[4] != 4 || dest[1] != 7)
    abort ();

  baz3 (&a_struct, source);
  if (a_struct.a_vector[7] != 1 || a_struct.a_vector[5] != 3)
    abort ();

  return 0;
}
Exemple #15
0
int main (void)
{
	// non-lazy reference to foo2
	p = &foo2;
	// lazy reference to foo4
	foo4();
	
	// non-lazy reference to bar2
	p = &bar2;
	// lazy reference to bar4 and bar1
	bar4();
	bar1();
   
   return 0;
}
Exemple #16
0
int
main ()
{
  if (foo1()[1] != 0x7f0f)
    __builtin_abort ();

  if (foo2()[1] != 0x7f0f)
    __builtin_abort ();

  if (foo3()[1] != 0x7f0f)
    __builtin_abort ();

  if (foo4()[1] != 0x77)
    __builtin_abort ();

  return 0;
}
Exemple #17
0
int
main(void)
{
  foo1 ();
  check ((signed char *)a, 16, sizeof (a), -1);

  foo2 ();
  check ((signed char *)b, 25, sizeof (b), 1);

  foo3 ();
  check ((signed char *)c, 19, sizeof (c), -1);

  foo4 ();
  check ((signed char *)d, 23, sizeof (d), 1);

  return 0;
}
void main()
{
    int r1, r2;
    int r3 = 22;

    if( r3 > 22 )
        g2 = 12;

    // print r1:
    // call foo3() always since it is both THEN and ELSE
    if( r1 > 20 )   
        foo3();
    else 
        foo3();

    // print r2:
    // call foo2() always - fall thru and default present:
    switch(r2) {
        case 1: 
        default: foo2();
    }

    // foo4 *not always* called:
    // g3 is DEFined always in foo3()
    while(r2>100) foo4(g3);

    // g0 is initialized:
    // print g6 since it is not DEFined always (foo4 is called conditionally)
    r1 = g0;
    r2 = g6;

    // g1 was used in foo1() therefore it needs to be printed:
    g1 = 12;

    // g5 was DEFined in foo2()
    printf( "%d %d\n", g5 );

    // need to print g7:
    printf( "g7 is not DEFined so need to print!%d\n", g7 );
}
Exemple #19
0
int
main ()
{
  if (foo1()[1] != 0x00ff00ff00ff00ffULL)
    __builtin_abort ();

  if (foo2()[1] != 0x0000ffff)
    __builtin_abort ();

  if (foo3a()[1] != 0xff00)
    __builtin_abort ();

  if (foo3b()[1] != 0x00ff)
    __builtin_abort ();

  if (foo4()[1] != 0xff)
    __builtin_abort ();

  if (foo5()[0] != 0xff00ff00ff00ff00ULL)
    __builtin_abort ();

  return 0;
}
Exemple #20
0
int foo3 (int c)
{
  return foo4 (c + getpid ());
}
Exemple #21
0
void foo3() {
  char* fname = "../files/test1_2";
  int fp2 = open(fname, O_RDONLY);
  close(fp2);
  foo4();
}
void foo3(int a0, long double a1) {
  foo4(1, 2, a0, a1);
}
Exemple #23
0
// CHECK-LABEL: define i32 @foo4t()
// CHECK: ret i32 376
// CHECK: }
int foo4t() {
  // 111 + 1 + 222 + 42 = 376
  return foo4(111) + foo4(99) + foo4(222) + foo4(601);
}
Exemple #24
0
uint32_t bar8(int a, uint32_t b, uint8_t c)
{
            return foo4(a, b, foo2(1, 2, 3));
}
Exemple #25
0
int foo5(int *a) {
	int b = 5;
	return foo4(a, &b);
}
Exemple #26
0
void testLua(lua_State* L) {
	printf("------------testLua------------\n");
	ELuna::LuaFunction<void> foo0(L, "foo0");
	ELuna::LuaFunction<void> foo1(L, "foo1");
	ELuna::LuaFunction<void> foo2(L, "foo2");
	ELuna::LuaFunction<void> foo3(L, "foo3");
	ELuna::LuaFunction<void> foo4(L, "foo4");
	ELuna::LuaFunction<void> foo5(L, "foo5");
	ELuna::LuaFunction<void> foo6(L, "foo6");
	ELuna::LuaFunction<void> foo7(L, "foo7");
	ELuna::LuaFunction<void> foo8(L, "foo8");
	ELuna::LuaFunction<void> foo9(L, "foo9");

	ELuna::LuaFunction<int> retFoo0(L, "retFoo0");
	ELuna::LuaFunction<int> retFoo1(L, "retFoo1");
	ELuna::LuaFunction<int> retFoo2(L, "retFoo2");
	ELuna::LuaFunction<int> retFoo3(L, "retFoo3");
	ELuna::LuaFunction<int> retFoo4(L, "retFoo4");
	ELuna::LuaFunction<int> retFoo5(L, "retFoo5");
	ELuna::LuaFunction<int> retFoo6(L, "retFoo6");
	ELuna::LuaFunction<int> retFoo7(L, "retFoo7");
	ELuna::LuaFunction<int> retFoo8(L, "retFoo8");
	ELuna::LuaFunction<int> retFoo9(L, "retFoo9");
	ELuna::LuaFunction<TestObj*> luaTestObjPointer(L, "luaTestObjPointer");
	ELuna::LuaFunction<TestObj&> luaTestObjRef(L, "luaTestObjRef");
	ELuna::LuaFunction<TestObj> luaTestObj(L, "luaTestObj");

	foo0();
	foo1(1);
	foo2(1,2);
	foo3(1,2,3);
	foo4(1,2,3,4);
	foo5(1,2,3,4,5);
	foo6(1,2,3,4,5,6);
	foo7(1,2,3,4,5,6,7);
	foo8(1,2,3,4,5,6,7,8);
	foo9(1,2,3,4,5,6,7,8,9);

	printf("retFoo0: %d\n", retFoo0());
	printf("retFoo1: %d\n", retFoo1(1));
	printf("retFoo2: %d\n", retFoo2(1,2));
	printf("retFoo3: %d\n", retFoo3(1,2,3));
	printf("retFoo4: %d\n", retFoo4(1,2,3,4));
	printf("retFoo5: %d\n", retFoo5(1,2,3,4,5));
	printf("retFoo6: %d\n", retFoo6(1,2,3,4,5,6));
	printf("retFoo7: %d\n", retFoo7(1,2,3,4,5,6,7));
	printf("retFoo8: %d\n", retFoo8(1,2,3,4,5,6,7,8));
	printf("retFoo9: %d\n", retFoo9(1,2,3,4,5,6,7,8,9));

	printf("luaTestObjPointer: \n");
	TestObj pObj = TestObj("TestObjPointer");
	TestObj* retPObj = luaTestObjPointer(&pObj);
	pObj.print();
	retPObj->print();

	printf("luaTestObjRef1: \n");
	TestObj objRef1("TestObjRef1");
	TestObj& retObjRef1 = luaTestObjRef(&objRef1);
	objRef1.print();
	retObjRef1.print();
	
	printf("luaTestObjRef2: \n");
	TestObj objRef2("TestObjRef2");
	TestObj& retObjRef2 = luaTestObjRef(objRef2);
	objRef2.print();
	retObjRef2.print();
	
	printf("luaTestObj: \n");
	TestObj obj("TestObj");
	TestObj retObj = luaTestObj(obj);
	obj.print();
	retObj.print();
	printf("pass refrence to luaFunction the same as object!\n");
}
Exemple #27
0
void foo5()
{
    char buf[128]; // Added to show non zero frame size in Memory stack
    strcpy(buf,"Added to show non zero frame size" );
    foo4();
}
Exemple #28
0
static int myfoo()
{
  return foo4();
}
Exemple #29
0
void __attribute__((near)) foo3 (void) { foo1(); foo4(); }
Exemple #30
0
int foo2() {
	return foo4();
}