-
Notifications
You must be signed in to change notification settings - Fork 44
Minor improvements to subsection on machine representation #1316
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
Open
gusthoff
wants to merge
14
commits into
AdaCore:main
Choose a base branch
from
gusthoff:content/advanced_ada/review/numerics/fixed_point_types/20260214
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c170d61
Adding integer type for overlay
gusthoff 0cb2f62
Adding Gen_Show_Info procedure
gusthoff be2d8b2
Replace calls to `Put_Line` by `Show_Info`
gusthoff 145a58a
Add headers to code example
gusthoff f67a67e
Adapting explanation after changes to code example
gusthoff b4749a4
Editorial change: Machine_Implementation => Machine_Representation
gusthoff 33288a1
Editorial change: correcting typo
gusthoff 51408c5
Editorial change: correct button in code example
gusthoff f9db140
Editorial change: adding empty line in code example
gusthoff 14abe96
Mentioning generic procedure
gusthoff 66f96d9
Editorial change: correcting typo
gusthoff acb85da
Editorial change: adding decimal non-exponential version of number
gusthoff 781b78d
Editorial change: adding missing word
gusthoff e109cb7
Adding assert for overlay
gusthoff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps add an assertion that T_Decimal'Size = T_Int_Decimal'Size?
No warning will be generated for a size mismatch if we use an overlay instead of an Unchecked_Conversion instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's a very good addition, thanks!
A question, though: should this pragma be rather placed in the package specification, as
T_Int_Decimalis always going to be used to create overlays?Also, would you say that such a pragma should always be used for overlays? If so, I should be mentioning that in the section about overlays, as well as adding a pragma to other code examples in this course that use overlays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like your idea of putting the assertion in the spec; the assertion documents a requirement that the client needs to be aware of.
For overlays in general, the sizes don't necessarily have to match , but you have to be careful to avoid a situation where you use an overlay to obtain a view of an object that is larger than the object really is (so you could be accessing whatever memory happens to follow the object).
For example, C might call Ada and on the Ada side it appears that we have a parameter of an enormous constrained array type and a second parameter specifying the actual length of the array. One might want to declare a subtype with the right bounds and then use an overlay to get a view of the array parameter that has the correct bounds. The two array subtypes would not be of the same size; that's the whole point.
Alignment is also an important consideration to be aware of. It is often a good idea to somehow ensure (perhaps via an assertion) that the address specified in an overlay satisfies the alignment requirements of the type in question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can mostly ignore what I said about adding an assertion to ensure correct alignment; when an object is declared with a specified address (as for an overlay), the compiler generates a run-time check that the address is properly aligned. But one still ought to take steps to ensure that this check won't fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bob reminds me that the compiler only emits the alignment check on machines that trap unaligned accesses (so not on x86). In the case where no check is performed, the user would have to decide whether they want to perform the check themselves (presumably via an assertion).