I am working on a project where I have to implement a handler for several functions, all of which have a number associated with them. The number that they are associated with is how the different functions are called. Knowing this I want to be able to group them into an array using the number as the index to the functions. The problem is, arrays need to have the same type of elements inside of them right? so how can I place these functions into an array?
这些职能是怎样编号的:
enum
{
SYS_HALT, /* Halt the operating system. */
SYS_EXIT, /* Terminate this process. */
SYS_EXEC, /* Start another process. */
SYS_WAIT, /* Wait for a child process to die. */
SYS_CREATE, /* Create a file. */
SYS_REMOVE, /* Delete a file. */
SYS_OPEN, /* Open a file. */
SYS_FILESIZE, /* Obtain a file s size. */
SYS_READ, /* Read from a file. */
SYS_WRITE, /* Write to a file. */
SYS_SEEK, /* Change position in a file. */
SYS_TELL, /* Report current position in a file. */
SYS_CLOSE, /* Close a file. */
};
And here is the list of function prototypes:
void halt (void) NO_RETURN;
void exit (int status) NO_RETURN;
pid_t exec (const char *file);
int wait (pid_t);
bool create (const char *file, unsigned initial_size);
bool remove (const char *file);
int open (const char *file);
int filesize (int fd);
int read (int fd, void *buffer, unsigned length);
int write (int fd, const void *buffer, unsigned length);
void seek (int fd, unsigned position);
unsigned tell (int fd);
void close (int fd);
www.un.org/sc/ctc
将所有职能纳入C的阵列或其他数据结构是否容易?
任何帮助都值得赞赏,这是对学校项目的支持,因此,一个小的例子或联系将非常有用,但我愿意自己制定解决办法。
增 编
www.un.org/Depts/DGACM/index_spanish.htm Edit:我想做些什么?
我想能够确定一些阵列,并按批次数的索引储存一个功能点。
//I don t know how to handle the type here
<some_type> system_call_arr[128];
system_call_arr[SYS_HALT] = halt;
system_call_arr[SYS_EXIT] = exit;
system_call_arr[SYS_EXEC] = exec;
// and so on....
www.un.org/Depts/DGACM/index_spanish.htm Edit 2
自2006年以来 Ben说,所有论点都符合32点论点,因此,我不能这样界定:
typedef int (*sys_func) (uint32_t, uint32_t, uint32_t);
sys_func syscall_array[128];
syscall_array[SYS_HALT] = (sys_func)halt;
//etc....
是否像这种良好做法一样?