Exemple #1
0
void twice_test() {
    NEW_TEST("twice");

    EQUAL_INT(4, twice(2));
    EQUAL_INT(4, twice(3));
    EQUAL_INT(1, twice(-1));
}
// address: 0x804837c
int main(int argc, char *argv[], char *envp[]) {
    __size32 eax; 		// r24

    eax = twice(argc);
    printf("Result is %d\n", eax);
    return 0;
}
int main() {
  int fn, arg1, arg2, result;
  byte buff[100];

  while (read_cmd(buff) > 0) {
    fn = buff[0];

    if (fn == 1) {
      arg1 = buff[1];
      arg2 = buff[2];
      result = sum(arg1, arg2);
    } else if (fn == 2) {
      arg1 = buff[1];
      result = twice(arg1);
    } else {
      exit(EXIT_FAILURE);
      return -1;
    }

    buff[0] = result;
    write_cmd(buff, 1);
  }

  return 0;
}
Exemple #4
0
int main () {
    int x =2; 
    int y =3;

    printf("%f\n", div(1, 2.0));
/* This is 0.5 because of the 2.0 being a floating number not an
 * integer since it has the '.o' at the end. This changes it to 
 * a  floating point division
 */
    printf("%d\n", div(twice(nonce(y)), nonce(twice(x))));
/* If you expand this out it would look like:
 * div(twice(x-x),nonce(x+x) then
 * twice(y-y)/twice(x) - twice(x)
 */
return 0;
}
Exemple #5
0
int main(void) {
    int arr[500] = {0};
    int i, j, res = 0;

    arr[0] = 1;

    for (i=0; i<1000; i++) {
        twice(arr);

        for (j=499; arr[j] == 0; j--);
        /* for (; j>=0; j--) { */
        /*     printf("%d", arr[j]); */
        /* } */
        /* printf("\n"); */

        /* res = 0; */
        /* for (j=0; j<500; j++) { */
        /*     res += arr[j]; */
        /* } */
        /* printf("%d\t%d\n", i+1, res); */
    }

    for (i=0; i<500; i++) {
        res += arr[i];
    }
    printf("%d\n", res);
    
    return 0;
}
int
main (int argc, char *argv[])
{
  printf ("4*TWICE(3) is %d\n", 4*TWICE(3));
  printf ("4*twice(3) is %d\n", 4*twice(3));
  return 0;
} // main
static void example_drv_output(ErlDrvData handle, char *buff, int bufflen)
{
    example_data* d = (example_data*)handle;
    char fn = buff[0], arg = buff[1], res;
    if (fn == 1) {
      res = twice(arg);
    } else if (fn == 2) {
      res = sum(buff[1], buff[2]);
    }
    driver_output(d->port, &res, 1);
}
Exemple #8
0
int main() {
int num = 5;
int *ptr = &num;

printf( "ptr stores address: %p\n" , ptr ) ;
printf( "*ptr dereferences value: %d\n\n" , *ptr ) ;
printf( "The num value is %d\n" , num ) ;
twice(ptr);
printf( "The num value is now %d\n", num ) ;
thrice( ptr ) ;
printf( "And now the num value is %d\n", num ) ;
return 0;
}
int
main (int argc, char *argv[])
{
  fprintf (stderr, "twice(1) is %lf\n", twice (1));
  fprintf (stderr, "twice(2) is %lf\n", twice (2));
  fprintf (stderr, "twice(3) is %lf\n", twice (3));
  fprintf (stderr, "twice(5) is %lf\n", twice (5));
  fprintf (stderr, "twice(6.0) is %lf\n", twice (6.0));
  fprintf (stderr, "twice(-1) is %lf\n", twice (-1));
  fprintf (stderr, "twice(-5) is %lf\n", twice (-5));
  return 0;
} // main
Exemple #10
0
int main(int argc, char **argv)
{
	printf("How old are you?: ");
	scanf("%d",&age);
	printf("How tall are you? (in feet): ");
	scanf("%f",&feet);
	printf("You are %d years old and %.1f feet tall\n",
		age, feet);
	half();
	twice();
	printf("But you're not really %d years old or %.1f feet tall",
		age,feet);
	return 0;
}
int main(void) {
    char s[] = "quick"; 
    char* t = twice(s);
    printf("%s\n", t); 
    free(t);

    char u[] = "jumps over"; 
    char* r = reverse(u);
    printf("%s\n", r); 
    free(r);
    
    char v[] = "lazy dog"; 
    char* d = drop(v, 'o');
    printf("%s\n", d);
    free(d);
}
int main() {
    int fn, arg1, arg2, result; 
    byte buff[100]; 
    
    while (read_cmd(buff) > 0) {
        fn = buff[0];
        if (fn == 1) {
            arg1 = buff[1];
            result = twice(arg1); 
        } else if (fn == 2) {
            arg1 = buff[1]; 
            arg2 = buff[2]; 
            /* debug -- you can print to stderr to debug
            fprintf(stderr, "calling sum %i %i\n", arg1, arg2); 
            */
            result = sum(arg1, arg2);
        }
        
        buff[0] = result; 
        write_cmd(buff, 1);
    }
}
int
main (int argc, char *argv[])
{
  long x;   // For doing pointless computations
  int i;    // Counter variable for loops

  struct timeval start;         // The start of a computation
  struct timeval finish;         // The end of a computation

  long elapsed;                 // Elapsed time in microseconds

  // Compute how long a lot of calls to TWICE take
  x = 0;
  gettimeofday(&start, NULL);
  for (i = 0; i < REPETITIONS; i++)
    {
      x += TWICE(3);
    }
  gettimeofday(&finish, NULL);
  elapsed = 1000000 * (finish.tv_sec - start.tv_sec)  
          + (finish.tv_usec - start.tv_usec);
  printf ("Using the macro, we spent %ld microseconds.\n", elapsed);
  printf ("Our result is %ld.\n\n", x);

  // Compute how long a lot of calls to TWICE take
  x = 0;
  gettimeofday(&start, NULL);
  for (i = 0; i < REPETITIONS; i++)
    {
      x += twice(3);
    }
  gettimeofday(&finish, NULL);
  elapsed = 1000000 * (finish.tv_sec - start.tv_sec)  
          + (finish.tv_usec - start.tv_usec);
  printf ("Using the procedure, we spent %ld microseconds.\n", elapsed);
  printf ("Our result is %ld.\n\n", x);

  return 0;
} // main
int main()
{
	int x;
	printf("\nThis will demonstrate function and label scopes.");
	printf("\nAll output is happening throung printf(), a function declared in the header file stdio.h, which is external to this program.");
	printf("\nEnter a number : ");
	scanf("%d",&x);
	
	switch(x%2){
		default:printf("\nCase labels in switch statements have scope local to the switch block.");
		case 0: printf("\nYou entered an even number.");
				  printf("\nIt's square is %d, which was computed by a macro. It has global scope within the program file.",sqr(x));
				  break;
		case 1: printf("\nYou entered an odd number.");
				  goto sayhello;
		jumpin: printf("\n2 times %d is %d, which was computed by a function defined in this file. It has global scope within the program file.",x,twice(x));
				  printf("\nSince you jumped in, you will now be greeted, again !");
	 sayhello: greet
	 			  if(x==-1)goto scram;
	 			  break;
	 };
	
	 printf("\nWe now come to goto, it's extremely powerful but it's also prone to misuse. It's use is discouraged and it wasn't even adopted by Java and later languages.");
	 				
	 if(x!=-1){
		 x = -1;     /*To break goto infinite loop.*/
	 	 goto jumpin;
	 	 }
	
	 scram: printf("\nIf you are trying to figure out what happened, you now understand goto.");
	 return 0;
}
// This instantiation of the "twice" template function with a "float" type
// will not have an `optnone` attribute because the template declaration was
// not affected by the pragma.
float container (float par) {
    return twice(par);
}
Exemple #16
0
int
main (void)
{
  int t = twice (1);
  return 0;
}
 int main() {
     int x = 6;
     std::cout << twice(x) << '\n'; 
     std::cout << twice(x + 2) << '\n'; 
     std::cout << twice(6) << '\n'; 
 }
Exemple #18
0
int main() {
  printf("twice 5 is %d\n", twice(5));
  return 0;
}
Exemple #19
0
int prod_twice(int i, int j) {
    return twice(i + j);
}
Exemple #20
0
int main(int argc,char *argv[])
{
	char *arglist[6],process_name[100],string[100];
	int p=0,i;
	printf("Child id = %d ,Parent id= %d",getpid(),getppid());
	unsigned long long int res=0;
	//Call twice if Command Line Arguments Present
	if(argc>=2)
	   {
		 res=twice(argv[1]);
	     printf(",Process Name= twice\n");
	   }
	else
	   {
		 printf("Insufficient Arguments");
		 exit(0);
	   }
	int start=atoi(argv[2]);
	int end=atoi(argv[3]);
	strcpy(string,argv[4]);
	for(i=start;i<=end;i++)
	{
	  if(string[i]==' ')
	  {
		process_name[p]='\0';
		 //Each process has name,input number,start and end index of input string ,new string followed by NULL
		 //if process is twice call twice process using execvp
		 if(!strcmp(process_name,"twice"))
		  {
		    arglist[0] = (char *)malloc(8*sizeof(char)); 
			strcpy(arglist[0],"./twice");
			arglist[1] = (char *)malloc(100*sizeof(char));
			sprintf(arglist[1],"%llu",res);
			arglist[2]=  (char *)malloc(10*sizeof(char)); 
			sprintf(arglist[2],"%d",i); 
			arglist[3]=  (char *)malloc(10*sizeof(char)); 
			sprintf(arglist[3],"%d",end); 
		    arglist[4]=  (char *)malloc(end*sizeof(char)); 
			strcpy(arglist[4],string);
		    arglist[5] = NULL;
			execvp("./twice",arglist);
			printf("\nThis statement is not executed if execvp succeeds.\n");
		  }
		 //if process is square call square process using execvp
		  else if(!strcmp(process_name,"square"))
		  {
		    arglist[0] = (char *)malloc(8*sizeof(char)); 
			strcpy(arglist[0],"./square");
			arglist[1] = (char *)malloc(100*sizeof(char));
			sprintf(arglist[1],"%llu",res);
			arglist[2]=  (char *)malloc(10*sizeof(char)); 
			sprintf(arglist[2],"%d",i); 
			arglist[3]=  (char *)malloc(10*sizeof(char)); 
			sprintf(arglist[3],"%d",end); 
		    arglist[4]=  (char *)malloc(end*sizeof(char)); 
			strcpy(arglist[4],string);
		    arglist[5] = NULL;
			execvp("./square",arglist);
			printf("\nThis statement is not executed if execvp succeeds.\n");
		  }
         //if process is half call half process using execvp
		  else if(!strcmp(process_name,"half"))
		  {
			arglist[0] = (char *)malloc(8*sizeof(char)); 
			strcpy(arglist[0],"./half");
			arglist[1] = (char *)malloc(100*sizeof(char));
			sprintf(arglist[1],"%llu",res);
			arglist[2]=  (char *)malloc(10*sizeof(char)); 
			sprintf(arglist[2],"%d",i); 
			arglist[3]=  (char *)malloc(10*sizeof(char)); 
			sprintf(arglist[3],"%d",end); 
		    arglist[4]=  (char *)malloc(end*sizeof(char)); 
			strcpy(arglist[4],string);
		    arglist[5] = NULL;
			execvp("./half",arglist);
			printf("\nThis statement is not executed if execvp succeeds.\n");
		  }
		  //if process is unknown
  		else if(strlen(process_name))
		 {
			  printf("Error! No such %s Process Exist",process_name);
			  exit(0);
		 }

		}
	 else
	  {
		//Stores the name of process
		process_name[p]=string[i];
		p++;
	  }
  }
	printf("\nFinal Result is %llu",res);
	return 0;
}
Exemple #21
0
constexpr int area = squarei(side); // { dg-error "side|argument" }
// error: squarei(side) is not a constant expression

int next(constexpr int x) // { dg-error "parameter" }
{ return x + 1; }

constexpr void f(int x)       // { dg-error "return type .void" }
{ /* ... */ }

constexpr int prev(int x)
{ return --x; }               // { dg-error "--" }

constexpr int g(int x, int n) // error: body not just ‘‘return expr’’
{
   int r = 1;
   while (--n > 0) r *= x;
   return r;
} // { dg-error "not a return-statement" }

constexpr int
bar(int x, int y) { return x + y + x * y; } // { dg-message "previously" }

int bar(int x, int y)	     // { dg-error "redefinition" }
{ return x * 2 + 3 * y; }

constexpr int twice(int x);  // { dg-message "never defined" }
enum { bufsz = twice(256) }; // { dg-error "" } twice() isn’t (yet) defined

constexpr int fac(int x)
{ return x > 2 ? x * fac(x - 1) : 1; } // OK