There's one thing that I noticed in CC65: When you write functions in C, then the resulting assembly file will not put them in the order that you actually wrote them in, but in the order of possible function head declarations.
So, if your code looks like this:
then B will be the first function defined in assembly:
It doesn't really make a difference in practice, but I'd like my functions to be in a definite order in memory if that's possible.
For example, if I have various functions in memory, then the ones that belong together should go after each other:
MovePlayer
MovePlayerHelperFunction
MoveOpponent
But in this case, since MovePlayer and MoveOpponent would be declared in the header file since they need to be called from another code file while MovePlayerHelperFunction is just a local function and is therefore only declared in the .c source file, the order in assembly would be this:
MovePlayer
MoveOpponent
MovePlayerHelperFunction
So, why is this even the case?
Declarations of function headers are just there to let other translation units know what the function looks like. I can write the same declaration as often as I want. It's just a reference point.
Why is the code not ordered according to the way I actually define the functions? Or is there any way to do this?
So, if your code looks like this:
Code:
void B(void);
void A(void);
void A(void)
{
}
void B(void)
{
}
void A(void);
void A(void)
{
}
void B(void)
{
}
then B will be the first function defined in assembly:
Code:
; ---------------------------------------------------------------
; void __near__ B (void)
; ---------------------------------------------------------------
.segment "CODE"
.proc _B: near
.segment "CODE"
rts
.endproc
; ---------------------------------------------------------------
; void __near__ A (void)
; ---------------------------------------------------------------
.segment "CODE"
.proc _A: near
.segment "CODE"
rts
; void __near__ B (void)
; ---------------------------------------------------------------
.segment "CODE"
.proc _B: near
.segment "CODE"
rts
.endproc
; ---------------------------------------------------------------
; void __near__ A (void)
; ---------------------------------------------------------------
.segment "CODE"
.proc _A: near
.segment "CODE"
rts
It doesn't really make a difference in practice, but I'd like my functions to be in a definite order in memory if that's possible.
For example, if I have various functions in memory, then the ones that belong together should go after each other:
MovePlayer
MovePlayerHelperFunction
MoveOpponent
But in this case, since MovePlayer and MoveOpponent would be declared in the header file since they need to be called from another code file while MovePlayerHelperFunction is just a local function and is therefore only declared in the .c source file, the order in assembly would be this:
MovePlayer
MoveOpponent
MovePlayerHelperFunction
So, why is this even the case?
Declarations of function headers are just there to let other translation units know what the function looks like. I can write the same declaration as often as I want. It's just a reference point.
Why is the code not ordered according to the way I actually define the functions? Or is there any way to do this?