コード例 #1
0
// -----------------------------------------------------------------
// Zero of the (derivative of the) error function
// Assuming that exactly one zero exists
static double zero(double (*fptr)(int, double*, double, double), int n,
                   double *c, double epsilon, double a, double b,
                   double prec) {

  int counter = 0;
  double h1, h2, hmid, mid;
  double prec2 = prec*prec;

  h1 = fptr(n, c, a, epsilon);
  h2 = fptr(n, c, b, epsilon);
  if (h1 * h1 < prec2)
    return a;
  if (h2 * h2 < prec2)
    return b;
  while(1) {
    mid = (a + b) / 2.0;
    counter++;
    hmid = fptr(n, c, mid, epsilon);
    if (hmid * hmid < prec2)
      return mid;
    if (h1 * hmid > 0.0) {
      a = mid;
      h1 = hmid;
    }
    else {
      b = mid;
      h2 = hmid;
    }
  }
  return 0.0;
}
コード例 #2
0
ファイル: ccalltest.c プロジェクト: Carreau/julia
int main() {
    printf("all of the following should be 1 except xs[259] = 0");
    a = 3;
    b = 259;
    fptr = (volatile int (*)(unsigned char x))&testUcharX;
    if ((((long)fptr)&((long)1)<<32) == 1) fptr = NULL;
    printf("compiled with: '%s'\nxs[3] = %d\nxs[259] = %d\ntestUcharX(3) = %d\ntestUcharX(%d) = %d\nfptr(3) = %d\nfptr(259) = %d\n",
        xstr(CC), xs[a], xs[b], testUcharX(a), b, testUcharX(b), fptr(a), fptr(b));
}
コード例 #3
0
int prod(int m,int n,int (*fptr)(int x))
	{
	if(m==n)
		{
		return fptr(m);
		}
	else
		{	
		return fptr(m) * prod(m+1,n,fptr);
		}	
	}
コード例 #4
0
/*
 * insertionsort()  sorts an array of integers
 * @array   : pointer to the integer array to be sorted
 * @n       : number of elements in the array
 * @fptr    : pointer to the comparison function
 *
 * employs insertion sort for sorting
 * returns 0 upon success
 */
int insertionSort(int *array, int n, bool(*fptr)(int, int)){
    /*array already sorted*/
    if(n < 2)
        return 0;
    int i = 0;
    int j = 0;
    int element = 0;
    /*out loop to iterate over all the elements to be inserted*/
    for(i = 1; i <= (n - 1); i++){
        element = *(array + i);
        /*inner loop to compare and shift elements*/
        for(j = (i - 1); j >= 0; j--){
            if(fptr(element, *(array + j))){
                /*condition for shifting*/
                *(array + j + 1) = *(array + j);
            }else{
                /*found the right position for this element*/
                *(array + j + 1) = element;
                break;
            }
        }
        /*insert the element at the start of the array*/
        if(j < 0){
            *(array) = element;
        }
    }
    return 0;
}
コード例 #5
0
void wrong_arguments_func_pointer_017 ()
{
    int flag;
    int (*fptr)(int,float);
    fptr =wrong_arguments_func_pointer_017_func_002;
    flag = fptr(1,4.5);
}
コード例 #6
0
void wrong_arguments_func_pointer_015 ()
{
    /*char str2[][15] = {{"STRING"},
    		       {"TEST"},{"STRING#"},{"TEST!"},{"TRIAL"}};*/
	int i;
	wrong_arguments_func_pointer_015_dst1_gbl = (char**) malloc(5*sizeof(char*));
    for(i=0;i<5;i++)
    {
    	wrong_arguments_func_pointer_015_dst1_gbl[i]=(char*) malloc(15*sizeof(char));
    }
	while(1)
	{
		void (*fptr)(char **);
	    fptr = (void (*)(char**))wrong_arguments_func_pointer_015_func_002;
	    fptr(wrong_arguments_func_pointer_015_dst1_gbl);/*Tool should detect this line as error*//*ERROR:Wrong arguments passed to a function pointer*/
	    break;
	}
	for(i=0;i<5;i++)
    {
		free(wrong_arguments_func_pointer_015_dst1_gbl[i]);
        wrong_arguments_func_pointer_015_dst1_gbl[i] = NULL;
    }
    free(wrong_arguments_func_pointer_015_dst1_gbl);
    wrong_arguments_func_pointer_015_dst1_gbl = NULL;
}
コード例 #7
0
void wrong_arguments_func_pointer_010 ()
{
	wrong_arguments_func_pointer_010_s_001 st;
	void (*fptr)(wrong_arguments_func_pointer_010_s_001);
	fptr = (void (*)(wrong_arguments_func_pointer_010_s_001))wrong_arguments_func_pointer_010_func_001;
	fptr(st);/*Tool should detect this line as error*//*ERROR:Wrong arguments passed to a function pointer*/
}
コード例 #8
0
/********************************************************************
* Function: 	JumpToApp()
********************************************************************/
void JumpToApp(void)
{
   printString("APP");
   void (*fptr)(void);
   fptr = (void (*)(void))0;
   fptr();
}
コード例 #9
0
ファイル: main.c プロジェクト: CarterTsai/freertos-plus
void command_prompt(void *pvParameters)
{
	char buf[128];
	char *argv[20];
        char hint[] = USER_NAME "@" USER_NAME "-STM32:~$ ";

	fio_printf(1, "\rWelcome to FreeRTOS Shell\r\n");
	while(1){
		fio_printf(1, "%s", hint);
		fio_read(0, buf, 127);
	
		int n=parse_command(buf, argv);

		/* will return pointer to the command function */
		//if (*argv[0]=='\0')
		cmdfunc *fptr=do_command(argv[0]);
		if(fptr!=NULL)
			fptr(n, argv);
		else if (*argv[0]!='\0')
			fio_printf(2, "\r\n\"%s\" command not found.\r\n", argv[0]);
		else
			fio_printf(1, "\r\n");
	}

}
コード例 #10
0
//---------------------------------------------------------------------------
// This function reads an OBJ file and generates vertices
// and triangles.  
// The function will throw ReadOBJError types if the file
// read is not entirely successful.
// Note that this function does not collapse duplicate
// vertices; it simply parses the file.  Freeform-specific
// operations such as removing duplicate vertices and checking
// if the file is a valid solid FF model should be performed at 
// a higher level.
//
//---------------------------------------------------------------------------
bool readOBJAscii(const char *filename,
                  VertContainer* verts,
                  TriContainer* tris,
                  hduBoundBox3Df* vertBox)
{
    FileHandle fptr(filename,"r");
    if (!fptr) return false;
    
    long numverts = 0;
    
    // Do first pass through file.  
    // Read vertices and other appropriate numerically 
    // ordered information (e.g. textures, normals) and store those.  
    // These will then be used as information to 
    // generate the entities (e.g. polygons, surfaces) during
    // the second pass.
    if (!readObjVertices(fptr,verts,vertBox))
        throw "readObjAscii vertex read failed.";
    // Do second pass through file.  
    // Read entities and construct using vertex information stored from 
    // first pass.
    if (verts->size() == 0)
        throw "readOBJAscii zero vertices read.";
        
    rewind(fptr);
    if (!readObjFaces(fptr,verts, tris))
        throw "readObjAscii faces read failed.";
    if (tris->size() == 0)
        throw "readOBJAscii zero faces read.";

    return true;
}
コード例 #11
0
ファイル: return.c プロジェクト: AndroidMarv/clang
int test27() {
  switch (j) {
  case 1:
    do { } while (1);
    break;
  case 2:
    for (;;) ;
    break;
  case 3:
    for (;1;) ;
    for (;0;) {
      goto done;
    }
    return 1;
  case 4:    
    while (0) { goto done; }
    return 1;
  case 5:
    while (1) { return 1; }
    break;
  case 6:
    fptr();
    break;
  default:
    return 1;
  }
  done: ;
}
コード例 #12
0
ファイル: Backend.cpp プロジェクト: nixtux/spring
// formats and routes the record to all sinks
void log_backend_record(int level, const char* section, const char* fmt, va_list arguments)
{
	const auto& sinks = log_formatter_getSinks();

	if (sinks.empty())
		return;

	cur_record.sec = section;
	cur_record.fmt = fmt;
	cur_record.lvl = level;

	// format the record
	log_formatter_format(&cur_record, arguments);

	// check for duplicates after formatting; can not be
	// done in log_frontend_record or log_filter_record
	const int cmp = (prv_record.msg[0] != 0 && STRCASECMP(cur_record.msg, prv_record.msg) == 0);

	cur_record.cnt += cmp;
	cur_record.cnt *= cmp;

	if (cur_record.cnt >= log_filter_getRepeatLimit())
		return;


	// sink the record into each registered sink
	for (log_sink_ptr fptr: sinks) {
		fptr(level, section, cur_record.msg);
	}

	if (cur_record.cnt > 0)
		return;

	memcpy(prv_record.msg, cur_record.msg, sizeof(cur_record.msg));
}
コード例 #13
0
ファイル: funclient.c プロジェクト: robbiebrown58/learn_c
int main(int argc, char **argv){

  extern int bar;

  extern int (*fptr) (void);

  extern struct Bozza buzz;
  
  printf("%s %d\n", "bar is ", bar);

  int c = somefunc();
  printf("%s%d\n", "Hello World, c is ", c);
  c = somefunc();
  printf("%s%d\n", "Hello World, c is ", c);
  c = somefunc();
  printf("%s%d\n", "Hello World, c is ", c);  
  c = somefunc();
  printf("%s%d\n", "Hello World, c is ", c); 

  c = fptr();
  printf("%s%d\n", "Hello World, c is ", c); 

  buzz.foobar = "Hello Foo";

  return 0;
}
コード例 #14
0
ファイル: main.c プロジェクト: itsmemyself/clockward_spiral
int main(int argc, char **argv) {
    void (*fptr)(int) = signal(101, foo);

    fptr(6667); //in this case => bar

    return 0;
}
コード例 #15
0
ファイル: func_pointer.c プロジェクト: AbsInt/itc-benchmarks
void func_pointer_014 ()
{
    int flag;
    int (*fptr)(int);
    fptr = func_pointer_014_func_002;
    flag = fptr(1);
}
コード例 #16
0
ファイル: zfile.c プロジェクト: ststeiger/ghostsvg
/* <string> .libfile <string> false */
int                             /* exported for zsysvm.c */
zlibfile(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    int code;
    byte cname[DEFAULT_BUFFER_SIZE];
    uint clen;
    gs_parsed_file_name_t pname;
    stream *s;
    gx_io_device *iodev_dflt;

    check_ostack(2);
    code = parse_file_name(op, &pname, i_ctx_p->LockFilePermissions, imemory);
    if (code < 0)
        return code;
    iodev_dflt = iodev_default(imemory);
    if (pname.iodev == NULL)
        pname.iodev = iodev_dflt;
    if (pname.iodev != iodev_dflt) { /* Non-OS devices don't have search paths (yet). */
        code = zopen_file(i_ctx_p, &pname, "r", &s, imemory);
        if (code >= 0) {
            code = ssetfilename(s, op->value.const_bytes, r_size(op));
            if (code < 0) {
                sclose(s);
                return_error(e_VMerror);
            }
        }
        if (code < 0) {
            push(1);
            make_false(op);
            return 0;
        }
        make_stream_file(op, s, "r");
    } else {
        ref fref;

        code = lib_file_open(i_ctx_p->lib_path, imemory, i_ctx_p, pname.fname, pname.len,
                             (char *)cname, sizeof(cname), &clen, &fref);
        if (code >= 0) {
            s = fptr(&fref);
            code = ssetfilename(s, cname, clen);
            if (code < 0) {
                sclose(s);
                return_error(e_VMerror);
            }
        }
        if (code < 0) {
            if (code == e_VMerror || code == e_invalidfileaccess)
                return code;
            push(1);
            make_false(op);
            return 0;
        }
        ref_assign(op, &fref);
    }
    push(1);
    make_true(op);
    return 0;
}
コード例 #17
0
ファイル: func_pointer.c プロジェクト: AbsInt/itc-benchmarks
void func_pointer_002 ()
{
	char buf[10] = "string";
	void (*fptr)(char);
	/* int a; */
	fptr = (void (*)(char ))func_pointer_002_func_001;
	fptr(buf[0]);/*Tool should detect this line as error*/ /*ERROR:Bad function pointer casting*/
}
コード例 #18
0
ファイル: func_pointer.c プロジェクト: AbsInt/itc-benchmarks
void func_pointer_007 ()
{
 	char buf[10] = "A string";
	char ** (*fptr)(char []);
	char ** a = NULL;
	fptr = (char ** (*)(char []))func_pointer_007_func_001;
	a =fptr(buf);/*Tool should detect this line as error*/ /*ERROR:Bad function pointer casting*/
}
コード例 #19
0
void wrong_arguments_func_pointer_002 ()
{
	char buf[10] = "string";
	int (*fptr)(char *);
	int a;
	fptr = (int (*)(char *))wrong_arguments_func_pointer_002_func_001;
	a =fptr(buf);/*Tool should detect this line as error*//*ERROR:Wrong arguments passed to a function pointer*/
}
コード例 #20
0
void wrong_arguments_func_pointer_001 ()
{
	int arr[5] = {1,2,3,4,5} ;
	int (*fptr)(int *);
	int a;
	fptr = (int (*)(int *))wrong_arguments_func_pointer_001_func_001;
	a =fptr(arr);/*Tool should detect this line as error*//*ERROR:Wrong arguments passed to a function pointer*/
}
コード例 #21
0
ファイル: bootldr.c プロジェクト: sidwarkd/waterworx-device
/********************************************************************
* Function:   JumpToApp()
*
* Precondition: 
*
* Input:    None.
*
* Output:   
*
* Side Effects: No return from here.
*
* Overview:   Jumps to application.
*
*     
* Note:     None.
********************************************************************/
void JumpToApp(void)
{ 
  void (*fptr)(void);

  INTDisableInterrupts();

  fptr = (void (*)(void))USER_APP_RESET_ADDRESS;
  fptr();
} 
コード例 #22
0
ファイル: avltest.c プロジェクト: loverabbit/kbs-redis
void AVL_PostTW(treenode * root, void (*fptr) (treenode *, void *), void *arg)
{                               /* postorder tree walk, note root must not be null */
    if (root->Lchild != NULL)
        AVL_PostTW(root->Lchild, fptr, arg);
    if (root->Rchild != NULL)
        AVL_PostTW(root->Rchild, fptr, arg);
    if (fptr != NULL)
        fptr(root, arg);
}
コード例 #23
0
raw_ios::pos_type raw_fstreambase<RawStream>::seekoff(raw_ios::off_type offs,
                                                      raw_ios::seekdir dir)
{
   int whence ;
   switch (dir)
   {
      case raw_ios::cur: whence = SEEK_CUR ; break ;
      case raw_ios::beg:
         if (!offs)
            return std::ftell(fptr()) ;
         whence = SEEK_SET ;
         break ;
      case raw_ios::end: whence = SEEK_END ; break ;

      default: return raw_ios::pos_type(-1) ;
   }
   return fseek_i(fptr(), offs, whence) ? -1 : std::ftell(fptr()) ;
}
コード例 #24
0
ファイル: fnptr.c プロジェクト: 8l/csolve
int main()
{
  int x = 3;
  int (*fptr)(int *) = foo;

  fptr(&x);

  return 0;
}
コード例 #25
0
ファイル: funcptr1.c プロジェクト: rosarion/cmsc313-fall-15
int main() {

    int a, b  ;
    int (* fptr) (int) ;

    a = 7 ;
    printf("a = %d\n", a) ;

    fptr = add3 ;
    b = fptr(a) ;
    printf("fptr(a) = %d\n", b ) ;

    fptr = add5 ;
    b = fptr(a) ;
    printf("fptr(a) = %d\n", b ) ;

    return 0 ;
}
コード例 #26
0
ファイル: 04shared.cpp プロジェクト: avcopan/cpppractice
int main()
{
  {
    std::FILE* f = std::fopen("test.txt", "r");
    boost::shared_ptr<FILE> fptr(f, deleter);
    std::fseek(fptr.get(), 42, SEEK_SET); // note -- this will cause a seg fault if test.txt is an empty file
  } // deleter(FILE*) is called as the file goes out of scope

  std::cout << "By now, the FILE has been closed!" << std::endl;
}
コード例 #27
0
ファイル: function_pointer.c プロジェクト: chaws/personal
int main()
{
    void (*fptr)();
    printf("func1 is at %p\n", func1);
    printf("func2 is at %p\n", func2);
    printf("Which to execute? ");
    scanf("%p", &fptr);
    fptr();
    return 0;
}
コード例 #28
0
ファイル: observe-noexcept.cpp プロジェクト: pjump/clang
// CHECK-LABEL: foo
void foo(int a, int b) {

    void (*fptr)(void) noexcept = fnoexcp;

    // CHECK: call {{.+}} @__kmpc_fork_call({{.+}} [[REGNAME2:@.*]] to void (i32*, i32*, ...)*), void ()** %{{.+}})
    #pragma omp parallel
    {
        fptr();
    }
    // CHECK: ret void
}
コード例 #29
0
ファイル: func_pointer.c プロジェクト: AbsInt/itc-benchmarks
void func_pointer_009 ()
{
	int ret;
	func_pointer_009_u_001 *p = NULL;
	func_pointer_009_u_001 (*fptr)();
	fptr = (func_pointer_009_u_001 (*)(void))func_pointer_009_func_001;
	*p = fptr();/*Tool should detect this line as error*/ /*ERROR:Bad function pointer casting*/
	ret = p->b;
	free(p);
	p= NULL;
}
コード例 #30
0
ファイル: ccalltest.c プロジェクト: BobPortmann/julia
int main() {
    fprintf(stderr,"all of the following should be 1 except xs[259] = 0\n");
    a = 3;
    b = 259;
    fptr = (volatile int (*)(unsigned char x))&testUcharX;
    if ((((size_t)fptr)&((size_t)1)) == 1) fptr = NULL;
    fprintf(stderr,"compiled with: '%s'\nxs[3] = %d\nxs[259] = %d\ntestUcharX(3) = %d\ntestUcharX(%d) = %d\nfptr(3) = %d\nfptr(259) = %d\n",
           xstr(CC), xs[a], xs[b], testUcharX(a), b, testUcharX((unsigned char)b), fptr(a), fptr(b));
    fprintf(stderr,"misc tests:\n");
    struct1 a = {352.39422e23, 19.287577};
    a = test_1(a);
}