Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
You're trying to use `PROCESS` before you defined it.
You need to use `struct _PROCESS*` instead inside of the structure, because at this time `PROCESS` does not exist yet.
The order you declares things in is important in C. You can't use something before it's definition.
The only exception being structure pointers, because you're telling the compiler "this is a pointer to something", so he knows the size of the object (sizeof(ptr_t)) and can allocate it for you, even if he doesnt know what's inside it.
Please note that this has nothing to do with OS Development...
For more details, please refer to a C programming course.
edit: replacing with struct _PROCESS and struct _THREAD won't work, no compiler errors but I get random garbage
Last edited by 22OsC on Sun Dec 12, 2021 12:29 am, edited 1 time in total.
I see you edited your post after my message ; why do you say it 'won't work' ? if you get no compiler errors it seems to be an improvement to me.
What kind of 'random garbage' are you getting, and where ? random garbage as compiler output ? random garbage at runtime ? what are you talking about ?
edit: replacing with struct _PROCESS and struct _THREAD won't work, no compiler errors but I get random garbage
Last edited by 22OsC on Sun Dec 12, 2021 12:29 am, edited 1 time in total.
I see you edited your post after my message ; why do you say it 'won't work' ? if you get no compiler errors it seems to be an improvement to me.
What kind of 'random garbage' are you getting, and where ? random garbage as compiler output ? random garbage at runtime ? what are you talking about ?
I create a process with name "main" with pid 1, when I try to get there stuff I get for name "3" or something like that and pid just random numbers
Do you have a repository where your code is ? You do realize that the problem you're describing is not only related to those structures, but also to the way you are using them...
By the way, out of curiosity, why do you use different variable types naming conventions : mixing `THREAD` with `PageTable` and `struct list_head` ?
vhaudiquet wrote:Do you have a repository where your code is ? You do realize that the problem you're describing is not only related to those structures, but also to the way you are using them...
By the way, out of curiosity, why do you use different variable types naming conventions : mixing `THREAD` with `PageTable` and `struct list_head` ?
are other structs, PageTable is from https://github.com/Absurdponcho/PonchoOS (the os is based from that tutorial) and struct list_head is from linux implementation I managed to get scheduler working and the problem was actually from memory implementation, I used `THREAD *thread = calloc(1, sizeof(THREAD));` but in the calloc I had a typo and now it's fixed. sorry for wasting your time
This is an easy mistake to fix. I'm going to assume that this is in a header file. To resolve this problem, in C, do something like (above your usage of struct process):
I'd encourage you however to take a bit of conventions from the Linux kernel, particularly involving the abuse/over-use of typedef to make C look "object-oriented". Avoid use of typedef struct foo foo; if you can, and instead use struct foo to make it clear what foo is.
vhaudiquet wrote:You're trying to use `PROCESS` before you defined it.
You need to use `struct _PROCESS*` instead inside of the structure, because at this time `PROCESS` does not exist yet.
This would solve the compilation error, but isn't necessary. You can just add appropriate forward declarations: