On Fri, 21 Dec 2007 18:00:42 -0800 (PST),
pr*******@gmail.com wrote in
comp.lang.c:
the problem is in some strange for me,
The problem is even stranger for us, because I read your entire post
and you didn't tell us what the problem is. All I see is some invalid
code. No description of compile or run time errors.
the program's goal will realize my own malloc and free function,
the project's h_file below:
#ifndef _MALLOCFREE_H_
You are not allowed to define identifiers beginning with an underscore
followed by an upper case letter, or beginning with two underscores.
Such symbols are reserved for the implementation in all contexts.
#define _MALLOCFREE_H_
#define PAGE_SIZE 4096
#define BUCKET_SIZE (PAGE_SIZE*1)
#define BUCKET_MASK (BUCKET_SIZE-sizeof(bucket_t))
struct object_t{
object_t *next;
The line above cannot be accepted by a C compiler. The identifier
"object_t" is not defined.
char data[0];
The line above cannot be accepted by a C compiler. The value inside [
and ] in the definition of an array, or an array member of a
structure, must be greater than 0.
};
struct bucket_t{
bucket_t *next, *prev;
Identifier "bucket_t" is undefined.
int object_size;
int object_num;
object_t *free_object;
int free_object_num;
object_t objects[0];
It is a constraint violation to have 0 or a negative number inside the
[ and ].
>
void *alloc();
void free(void *ptr);
};
struct pool_t{
bucket_t dummy;
int object_size;
bucket_t *new_bucket();
void free_bucket(bucket_t *b);
void *alloc();
void free(void *ptr);
};
#endif
If your problem is that this will not compile with a C compiler, then
the compiler is correct.
If you are using some language other than C, you are posting in the
wrong group, and you need to post in a group for the language you are
actually using. If you are using the language that I think you are,
the identifier "_MALLOCFREE_H_" and the arrays with 0 length are
invalid in that language as well.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://c-faq.com/
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html