Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

screen: modernize prototypes #1781

Merged
merged 6 commits into from
Jan 1, 2024

Conversation

ccoffing
Copy link
Contributor

Hi @ghaerr and @tyama501 ,

I see several ways that screen could be made smaller and improved, but the old function prototypes are so difficult to work with that I decided to modernize the source code first. I reformatted in the ELKS style (using the indent.pro settings that @ghaerr provided a while back) and then manually converted the K&R prototypes to ANSI.

More focused improvements can now be done in subsequent PRs, which will hopefully be more readable without this noise in the way.

To be sure I didn't break anything in the process, I built master and then disassembled the object files, and then built this branch and disassembled, and then diff'd. The only difference is that the modernized prototypes caused the compiler to reorder a couple of instructions. This does not appear to be a functional change.

$ ia16-elf-objdump  -d -m i8086 screen.o  > screen.new
$ diff screen.old  screen.new 
3046,3047c3046,3047
<   1b:	8b 56 08             	mov    0x8(%bp),%dx
<   1e:	89 df                	mov    %bx,%di
---
>   1b:	89 df                	mov    %bx,%di
>   1d:	8b 56 08             	mov    0x8(%bp),%dx
3076,3077c3076,3077
<   75:	c7 46 08 01 00       	movw   $0x1,0x8(%bp)
<   7a:	89 5e 0a             	mov    %bx,0xa(%bp)
---
>   75:	89 5e 0a             	mov    %bx,0xa(%bp)
>   78:	c7 46 08 01 00       	movw   $0x1,0x8(%bp)
3193,3194c3193,3194
<  19d:	8b 56 08             	mov    0x8(%bp),%dx
<  1a0:	8b 7e 0a             	mov    0xa(%bp),%di
---
>  19d:	8b 7e 0a             	mov    0xa(%bp),%di
>  1a0:	8b 56 08             	mov    0x8(%bp),%dx
$ diff ansi.old ansi.new
$

@ghaerr
Copy link
Owner

ghaerr commented Dec 31, 2023

Thanks for the ANSI C conversions @ccoffing! Moving source from K&R to ANSI helps a lot for stopping potential bugs with parameter mismatches, for sure.

To be sure I didn't break anything in the process, I built master and then disassembled the object files, and then built this branch and disassembled, and then diff'd.

Wow, nice showing nothing changed; I don't know why the few instructions have been reordered, but nothing to worry about.

A small issue is that functions with no parameters, such as:

int InitTerm(void);

changing to

int InitTerm();

leave open the possibility of passing arguments to InitTerm, which is allowed with ANSI C when no (void) used, when the function should in fact never be passed any. Is that your understanding also?

Thank you!

@ccoffing
Copy link
Contributor Author

A small issue is that functions with no parameters, such as:

Oh, right... my C++ side is showing through. I'll fix.

@ghaerr ghaerr merged commit 88c288b into ghaerr:master Jan 1, 2024
1 check passed
@ccoffing ccoffing deleted the screen-modernize-prototypes branch January 7, 2024 04:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants