473,466 Members | 1,436 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

some strange for me (addition)

the problem is in some strange for me,
the program's goal will realize my own malloc and free function,
the project's h_file below:
#ifndef _MALLOCFREE_H_
#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;
char data[0];
};

struct bucket_t{
bucket_t *next, *prev;
int object_size;
int object_num;
object_t *free_object;
int free_object_num;
object_t objects[0];

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
Dec 22 '07 #1
5 1361
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
Dec 22 '07 #2
pr*******@gmail.com wrote:
the problem is in some strange for me,
the program's goal will realize my own malloc and free function,
the project's h_file below:
#ifndef _MALLOCFREE_H_
#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;
char data[0];
};

struct bucket_t{
bucket_t *next, *prev;
int object_size;
int object_num;
object_t *free_object;
int free_object_num;
object_t objects[0];

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
I assume this is C++. Ask in comp.lang.c++.

--
Thad
Dec 22 '07 #3
pr*******@gmail.com writes:
the problem is in some strange for me,
the program's goal will realize my own malloc and free function,
the project's h_file below:
#ifndef _MALLOCFREE_H_
#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;
char data[0];
};

struct bucket_t{
bucket_t *next, *prev;
int object_size;
int object_num;
object_t *free_object;
int free_object_num;
object_t objects[0];

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
You've started a new thread, unconnected to what was being discussed
before. (I *think* you were discussing something similar earlier, but
I'm not going to go back and check.)

Looking at the code you just posted, you attempt to declare arrays of
length 0. This is illegal. You also appear to be writing C++, not C.

What was your question?

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Dec 22 '07 #4
On Fri, 21 Dec 2007 18:00:42 -0800, profjwang wrote:
the problem is in some strange for me,
You need to describe the problem.
struct object_t{
object_t *next;
char data[0];
This is not allowed in C. The size of an array must be at east 1.
Note that some implementations allow zero-size arrays as an extension but
its nonportable and not standard.
struct bucket_t{
bucket_t *next, *prev;
int object_size;
int object_num;
object_t *free_object;
No type "object_t" has been defined.
Have you missed some code out?
Note that C is not C++, and a struct definition does not introduce a type
alias.
void *alloc();
void free(void *ptr);
Better not to declare your own prototypes for standard functions - use
the appropriate header.
bucket_t *new_bucket();
Function pointer inside a struct. You're thinking of C++
void free(void *ptr);
Definitely not C....
Dec 22 '07 #5
On Sat, 22 Dec 2007 10:38:18 GMT, Mark McIntyre
<ma**********@spamcop.netwrote:
On Fri, 21 Dec 2007 18:00:42 -0800, profjwang wrote:
struct bucket_t{
bucket_t *new_bucket();

Function pointer inside a struct. You're thinking of C++
s/pointer //
If it was a pointer it would be valid C.

- formerly david.thompson1 || achar(64) || worldnet.att.net
Jan 7 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ben | last post by:
Hi all, I'm trying to figure out how how complex map, filter and reduce work based on the following piece of code from http://www-106.ibm.com/developerworks/linux/library/l-prog.html : ...
0
by: serge calderara | last post by:
Dear all, I have a really strange beaviour in my application. First of all I have a single plugin interface named IPlugIn which as been build in a separate project library named PLugin.dll...
193
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I...
4
by: deepukutty | last post by:
HI all, I am using IE(Internet Explorer) as my default browser for asp.net application development. Today i faced a strange problem. When ever an exception occured in the page ....application...
8
by: Spam Trap | last post by:
I am getting strange resizing problems when using an inherited form. Controls are moving themselves seemingly randomly, but reproducibly. "frmBase" is my base class (a windows form), and...
4
by: naknak4 | last post by:
Introduction This assignment requires you to develop solutions to the given problem using several different approaches (which actually involves using three different STL containers). You will...
0
by: atarumorooka | last post by:
Hello, yes..it must be hard to try and help someone else coding but today is a full week of sadness and stress for IE CSS rendering and I need your help. Here you have a link that looks nice with...
1
by: tohnsm | last post by:
Hi. I have been trying to create a cookie container. But the cookie I have stored is not correct. Below is the code: request = CType(WebRequest.Create("....."), httpWebRequest) ...
1
by: Mark Morss | last post by:
Is this the place to ask a win32com.client question? I am a unix person trying to run on windows, so I have little familiarity with this module. I have this code: import win32com.client ...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.