FT_Memoryの具体的な定義とは?

このQ&Aのポイント
  • FT_MemoryはFreetypeライブラリ内で使用されるオブジェクトで、メモリ管理に関連した機能を提供します。
  • FT_Memoryはstruct FT_MemoryRec_という構造体で定義されており、メモリの割り当て、解放、再割り当てなどを行う関数ポインタを持ちます。
  • FT_Alloc_Funcという関数ポインタ型が使用され、メモリの割り当てを行う関数が指定されます。
回答を見る
  • ベストアンサー

FT_Memoryというオブジェクトは具体的にどのように定義されているの?

Cygwin+vim+ctagで タグジャンプでFT_Memoryを調べていたら、 \cygwin\usr\include\freetype2\freetype\ftsystem.h内に typedef struct FT_MemoryRec_* FT_Memory; と struct FT_MemoryRec_ { void* user; FT_Alloc_Func alloc; FT_Free_Func free; FT_Realloc_Func realloc; }; と typedef void* (*FT_Alloc_Func)( FT_Memory memory,long size ); と いう風にループタグジャンプしていまい、ずーっと盥回し状態です。 FT_Memoryというオブジェクトは具体的にどのように定義されているのでしょうか?

質問者が選んだベストアンサー

  • ベストアンサー
  • MetalKing
  • ベストアンサー率57% (15/26)
回答No.1

typedef struct FT_MemoryRec_* FT_Memory;   ↓ FT_MemoryはFT_MemoryRec_型のオブジェクトを指すポインタ typedef void* (*FT_Alloc_Func)( FT_Memory memory,long size );   ↓ FT_Alloc_FuncはFT_Memoryとlongを引数に持ち、void*を返す関数のポインタ   ↓ C言語の文法でメンバー関数を定義したいのでしょう

YYoshikawa
質問者

補足

有難うございます。 > typedef struct FT_MemoryRec_* FT_Memory; >   ↓ > FT_MemoryはFT_MemoryRec_型のオブジェクトを指すポインタ つまり、FT_Memoryにはアドレス(数値)が格納される型なのでlong型という事なのですね。 > typedef void* (*FT_Alloc_Func)( FT_Memory memory,long size ); > FT_Alloc_FuncはFT_Memoryとlongを引数に持ち、void*を返す関数のポインタ > C言語の文法でメンバー関数を定義したいのでしょう FT_Alloc_Funcはlong(FT_Memory)型とlong型を引数に持ち、void*を返す関数のポインタ と言ってもいいんですかね。 これなら堂堂巡りせずに済み、納得出来ます。

関連するQ&A

  • 構造体の纏め方

    関数のポインタを使用して、 /* プロトタイプ宣言 */ void func1 ( void ); void func2 ( void ); void func3 ( void ); /*******************/ /* プロトタイプ纏める */ void ( *funcs[] ) ( void ) = { func1, func2, func3 }; /*********************/ と言うのが、構造体でも出来ないでしょうか?と言うのが質問です。 変数(添字)によって、見るべき構造体を自由に変更させたいと言うのが主な使用方法です。 typedef struct _tag { int arg1; int arg2; } tag; tag watch1 , watch2 , watch3; とある変数が1なら、watch1、とある変数が2なら、watch2、とある変数が3なら、watch3を見ると言うようなプログラムにしたくて、質問しました。 witch文を使うしかないのでしょうか? 良き回答、お待ちしています。

  • C言語 プロトタイプ宣言

    分割コンパイルした場合のプロトタイプ宣言について質問です。 以下のプログラムをコンパイルすると警告がでます。 プロトタイプ宣言は関数を利用する側と定義側両方に必要と理解していたのですが・・・ どなたか教えていただけますでしょうか。 windows7 cygwin gccでコンパイル エラーメッセージ $ gcc -o testMain.exe testMain.c testKioku.c testKioku.c:9: 警告: conflicting types for 'func1' testKioku.c:3: 警告: previous declaration of 'func1' was here testKioku.c:17: 警告: conflicting types for 'func2' testKioku.c:4: 警告: previous declaration of 'func2' was here ソース testMain.c #include <stdio.h> void func1(void); void func2(void); int cnt=5; main(){ printf("main=%d\n",cnt); func1(); func2(); } testKioku.c #include <stdio.h> void func1(void); void func2(void); extern int cnt; func1() { cnt++; printf("func1 global cnt=%d\n",cnt); func2(); } func2() { printf("func2 global cnt=%d\n",cnt); }

  • DLLの関数呼び出しで引数があるとフリーズしてしまう。

    はじめまして、C言語勉強中の初心者です。 現在、DLLに定義されている関数を呼び出すことを試していますが、うまくいかないので質問させて頂きました。 DLLには2つの関数が定義されています。  1.void Hello()  2.void HelloEx(char *pval); 1の関数を呼び出す場合は異常なく終了するのですが、2の関数を呼び出すと、フリーズしてしまいます。 フリーズする原因が分からないので、教えて頂ければと思います。 以下にソースを掲載します。 因みにコンパイラはBCC5.5.1を使用しています。 ***************************************************** DLL(Hello.c) [bcc32 -WD Hello.c] ***************************************************** #include <windows.h> #include <stdio.h> __declspec(dllexport) void CALLBACK Hello(void) { printf("Hello!\n"); } __declspec(dllexport) void CALLBACK HelloEx(char *pVal) { printf("Hello!%s\n", pVal); } ***************************************************** EXE(HelloTest.c)[bcc32 -L HelloTest.c] ***************************************************** #include <windows.h> #include <stdio.h> typedef void (*Hello)(void); typedef void (*HelloEx)(char*); int main(void) { HMODULE hMod; Hello func; HelloEx funcEx; hMod = LoadLibrary( "Hello.dll" ); if(!hMod) return FALSE; func = (Hello)GetProcAddress( hMod, "Hello"); if(!func) return FALSE; funcEx = (HelloEx)GetProcAddress( hMod, "HelloEx"); if(!funcEx) return FALSE; func(); funcEx("World"); FreeLibrary(hMod); return 0; } *********************************************** 以上

  • 仮引数の変数をローカル変数に格納する理由について

    プログラムの多くは、仮引数のポインタを一度ローカル変数に格納して使っていますが、なぜでしょうか?データが壊れてしまったりするのでしょうか・・・ typedef struct _LIST{ int value; struct LIST *next; struct LIST *prev; }LIST,*LIST_PTR; void func(LIST_PTR list, char *str){ LIST_PTR wk_list; char *wk_str; wk_list = list; wk = str;

  • Cのローカル変数でstatic以外の使い方?

    C言語の課題について教えてください [課題] 以下の関数がある。各関数の引数、変数は自由に設定していい ・int main() ・void func() ・Point *get() { /* 構造体のアドレスを返す */ } ・構造体 typedef struct { int x; int y; int h; int w; }Point; 問題 main関数から、func関数を経由して、get関数を経由し値を取得し、表示する 以下が考えたソースになりますが、これだと、 ローカル変数でstaticを使っているので、get関数が固定値ではなく、 取得のたびに値が変わるような場合には、だめだといわれました。 考えたのですがよくわからないので、どういう場合に駄目なのかと、 どのように修正すればいいのか教えてください。 #include <stdio.h> typedef struct { int x; int y; int h; int w; }Point; void func(Point **); Point *get(); int main(void){ Point *get; func(&get); printf("get.x:[%d]\n",get->x); printf("get.y:[%d]\n",get->y); printf("get.h:[%d]\n",get->h); printf("get.w:[%d]\n",get->w); return 0; } void func(Point **pw){ *pw = get(); printf("Wrapper: pw==%p\n",pw); } Point *get(void) { static Point pget; pget.x = 2; pget.y = 2; pget.h = 30; pget.w = 40; return &pget; }

  • 構造体と配列の関係

    #include<stdio.h> typedef struct stat { char alph; int count; }Stat; int main(void) { Stat al[26]; al.alphにアルファベットaからzを、al.countを全て0とし、各アルファベットに対するカウントを取れるようにしたいのですが、どのように書けば良いでしょうか?

  • 相互に参照する構造体について

    Cプログラミングについての質問です。よろしくお願いします。 以下のヘッダファイル(defx.h, defy.h)および、mainファイルが正しくコンパイルされるということなのですが、自分の環境(WinXP下でのgcc(MinGW))ではエラーが出ます。 エラー内容は error: redefinition of typedef 'SY' error: previous declaration of 'SY' was here error: redefinition of typedef 'SY' error: previous declaration of 'SY' was here です。 <defx.h> #if !defined(__SX) #define __SX typedef struct __sy SY; typedef struct { int a; SY *b; } SX; #endif <defy.h> #if !defined(__SY) #define __SY #include "defx.h" typedef struct __sy { int c; SX d; } SY; #endif mainファイルについては #include "defx.h" #include "defy.h" int main(void) { SX s; SY t; } 以上ですが、 よろしくお願い致します。

  • C言語プログラムエラーについて

    構造体とポインタを使って関数電卓のプログラムを作ってコンパイルしたのですがひとつだけエラーがでて困っています。親切な方回答よろしくお願いします。 ソースコード↓ #include<stdio.h> #include<string.h> #include<math.h> int main(void) { int i; double result; char inp_buf[30]; double input_d; typedef struct{ char*f_name; double(*func)(double); }FUNC_TBL; FUNC_TBL f_tbl[] = { { "sin",sin }, { "cos",cos }, { "tan",tan }, { "exp",exp }, }; printf( ">" ); scanf( "%s %lf", inp_buf, &input_d); for( i=0;i< sizeof(f_tbl)/sizeof(FUNC_TBL);i++) { if(!strcmp(f_tbl[i],f_name,inp_buf)) { 29行目→ result = f_tbl[i],func(input_d); } } printf("%lf\n",result); return 0; } エラーメッセージ↓ (29):error C2440:`=`:`FUNC_TBL`から`double`に変換できません。

  • free()について

    free()の使いかたがよくわかりません。struct_createで次のように確保した領域を解放するのに、『free(s);』だけではダメだということですが、どうしてダメなのか、そしてどうしたらいいのかがわかりません。初心者なので詳しく教えていただけるとありがたいです。 #include<stdlib.h> struct cell{ struct cell *next; int datum; }; struct stack{ struct cell *head; }; struct stack * stack_create() { struct stack *s; s=malloc(sizeof(struct stack)); s->head=NULL; return s; } void stack_free(struct stack *s) { free(s); }

  • global変数をブロック内から参照したい

    可変長配列の可変長配列を飲み込んで 吐き出すコードです global変数 *st_memory こいつをブロック内から参照するには どない書けば良いのでしょうか 構造体とか他の関数から引っぱり出しても 何故にかSegmentation faultで弾かれます mallocとかgotoの処理は無視して下さい _________________________ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> #define MAX 256 typedef enum{ SUCCESS, EOF_FILE, MEM_OVER }Add_List; char *st_memory = NULL; //global void free_buffer(void){ free(st_memory); st_memory = NULL; } Add_List add_char(const int ch,int *count){ static int buffer = 0; assert(buffer >= *count); if(buffer == *count){ st_memory = (char *)realloc(st_memory, (buffer + MAX) * sizeof(char)); if(st_memory == NULL)return MEM_OVER; buffer += MAX; }// END if st_memory[*count] = ch; (*count)++; return SUCCESS; } // END add_char(const int,int); Add_List read_line(FILE *fp,char **line){ int ch,used_line = 0; Add_List status = SUCCESS; while((ch = getc(fp)) != EOF){ if(ch == '¥n'){ status = add_char('¥0',&used_line); if(status != SUCCESS)goto FUNK_END; break; } // END if status = add_char(ch,&used_line);// MAIN if(status != SUCCESS)goto FUNK_END; }// END while if(ch == EOF){ if(used_line > 0){ status = add_char('¥0',&used_line); if(status != SUCCESS)goto FUNK_END; }else{ status = EOF_FILE; goto FUNK_END; } // END if } // END if line[0] = (char *)malloc(sizeof(char) * used_line); if(line[0] == NULL){ status = MEM_OVER; goto FUNK_END; } strcpy(line[0],st_memory);// MAIN FUNK_END: if(status != SUCCESS)free_buffer(); return status; }// END read_line(FILE *,char **); char ** add_line(char **text_file,char *mem_line, int *line_alloc_num,int *line_num){ assert(*line_alloc_num >= *line_num); if(*line_alloc_num == *line_num){ text_file = (char **)realloc(text_file, (*line_alloc_num + MAX) * sizeof(char)); if(text_file == NULL)exit(0); *line_alloc_num += MAX; } // END if text_file[*line_num] = mem_line; (*line_num)++; return text_file; } // END add_line(char **,char *,int *,int *); char ** read_file(FILE *fp,int *line_p){ char **text_file = NULL; int line_alloc_num = 0; int line_num = 0; char *mem_line = NULL; while(read_line(fp,&mem_line) == 0){ text_file = add_line(text_file, mem_line,&line_alloc_num,&line_num); } // END while text_file = (char **)realloc(text_file, line_alloc_num * sizeof(char)); if(text_file == NULL)exit(0); *line_p = line_num; return text_file; } // END read_file((FILE *,int *); int main(void){ char **text = NULL; int i,line_num = 0; text = read_file(stdin,&line_num); printf("¥n"); for(i=0;i<line_num;i++) printf("%s¥n",text[i]); return 0; } ______________________