What's the point of package
#2409
Replies: 4 comments 1 reply
-
The |
Beta Was this translation helpful? Give feedback.
-
Yunky86 escribió/skribis/wrote/scrit (2023-03-25T04:53:53-0700):
what's the use of `package`?
I've had the very same doubt from the first time I used Odin. 1) A
package is the content of a directory; 2) the package name can be
different than its directory name; 3) there seems to be no `@()`
attribute applicable to `package`. So what's the `package` keyword
useful for?
…--
Marcos Cruz
http://programandala.net
|
Beta Was this translation helpful? Give feedback.
-
Jeroen van Rijn escribió/skribis/wrote/scrit (2023-03-25T05:21:52-0700):
The `package` directive at the top of the file is used in the ABI. Say
you import `fmt`, then if you call `fmt.printf`, that `fmt.printf` is
the symbol name the linker will see.
So the only purpose of adding `package` to all of the files of a package
is to make the package name explicit in the code itself, and also allow
it to be different from the directory's.
I always wondered why `package` is required in all files, instead of
using the directory name as package name.
…--
Marcos Cruz
http://programandala.net
|
Beta Was this translation helpful? Give feedback.
-
In 2022 this was questioned in a comment to the video Compiler Demo - Introspection, Modules, and Record Layout and @gingerBill responded it:
|
Beta Was this translation helpful? Give feedback.
-
Sorry but whenever I want to build an odin file, I usually think I need to put in my package name not directory.
If not the directory what's the use of
package
?Beta Was this translation helpful? Give feedback.
All reactions