このチュートリアルに従ってください: http://www.jamesmolloy.co.uk/tutorial_html/7.-The%20Heap.html
次のエラーがあります。
source/ordered_array.c: In function ‘insert_ordered_array’:
source/ordered_array.c:43:67: error: expected identifier before ‘[’ token
source/ordered_array.c:43:67: error: too few arguments to function ‘array->less_than’
make: *** [obj/ordered_array.o] Error 1
私のコンパイラから。チュートリアルを完全に実行したため、何もわかりません。
関連するファイルは次のとおりです。
注文配列.h:
// ordered_array.h -- Interface for creating, inserting and deleting
// from ordered arrays.
// Written for JamesM's kernel development tutorials.
#ifndef ORDERED_ARRAY_H
#define ORDERED_ARRAY_H
#include "common.h"
/**
This array is insertion sorted - it always remains in a sorted state (between calls).
It can store anything that can be cast to a void* -- so a u32int, or any pointer.
**/
typedef void* type_t;
/**
A predicate should return nonzero if the first argument is less than the second. Else
it should return zero.
**/
typedef s8int (*lessthan_predicate_t)(type_t,type_t);
typedef struct
{
type_t *array;
u32int size;
u32int max_size;
lessthan_predicate_t less_than;
} ordered_array_t;
/**
A standard less than predicate.
**/
s8int standard_lessthan_predicate(type_t a, type_t b);
/**
Create an ordered array.
**/
ordered_array_t create_ordered_array(u32int max_size, lessthan_predicate_t less_than);
ordered_array_t place_ordered_array(void *addr, u32int max_size, lessthan_predicate_t less_than);
/**
Destroy an ordered array.
**/
void destroy_ordered_array(ordered_array_t *array);
/**
Add an item into the array.
**/
void insert_ordered_array(type_t item, ordered_array_t *array);
/**
Lookup the item at index i.
**/
type_t lookup_ordered_array(u32int i, ordered_array_t *array);
/**
Deletes the item at location i from the array.
**/
void remove_ordered_array(u32int i, ordered_array_t *array);
#endif // ORDERED_ARRAY_H
order_arrays.c:
// ordered_array.c -- Implementation for creating, inserting and deleting
// from ordered arrays.
// Written for JamesM's kernel development tutorials.
#include "ordered_array.h"
s8int standard_lessthan_predicate ( type_t a, type_t b )
{
return ( a < b ) ? 1:0;
}
ordered_array_t create_ordered_array ( u32int max_size, lessthan_predicate_t less_than )
{
ordered_array_t to_ret;
to_ret.array = ( void* ) kmalloc ( max_size * sizeof ( type_t ) ) ;
memset ( to_ret.array, 0, max_size*sizeof ( type_t ) );
to_ret.size = 0;
to_ret.max_size = max_size;
to_ret.less_than = less_than;
return to_ret;
}
ordered_array_t place_ordered_array ( void *addr, u32int max_size, lessthan_predicate_t less_than )
{
ordered_array_t to_ret;
to_ret.array = ( type_t *) addr;
memset ( to_ret.array, 0, max_size*sizeof ( type_t ) );
to_ret.size = 0;
to_ret.max_size = max_size;
to_ret.less_than = less_than;
return to_ret;
}
void destroy_ordered_array ( ordered_array_t *array )
{
// kfree ( array -> array );
}
void insert_ordered_array ( type_t item, ordered_array_t *array )
{
ASSERT ( array -> less_than );
u32int iterator = 0;
---------------------------------------Faulting Line------------------------------------
while ( iterator < array -> size && array -> less_than ( array ->[iterator], item ) )
----------------------------------------------------------------------------------------
iterator++;
if ( iterator == array -> size ) // just add at the end of the array.
array -> array [array -> size++] = item;
else
{
type_t tmp = array -> array[iterator];
array -> array[iterator] = item;
while ( iterator < array -> size )
{
iterator++;
type_t tmp2 = array -> array[iterator];
array -> array[iterator] = tmp;
tmp = tmp2;
}
array -> size++;
}
}
type_t lookup_order_array ( u32int i, ordered_array_t *array )
{
ASSERT ( i < array -> size );
return array -> array [i];
}
void remove_ordered_array ( u32int i, ordered_array_t *array )
{
while ( i < array -> size )
{
array -> array[i] = array -> array[i+1];
i++;
}
array -> size--;
}
コンパイルエラーが発生する理由は何ですか?