| LB wrote: |
|---|
| At the end of compiling the program there are 2 functions, but if we removed x, y, and z, there would be 0 functions. |
But that wouldn't be a valid program according to the standard because it has no main function. (A library isn't a valid program until it's linked, statically or dynamically, with something that is. A library is basically a special case of object files.)
| In other words, you need to be able to take the address of it for it to be a function by my definition. |
Earlier you said that assembly labels aren't procedures, but you can take the address of them. In fact the assembler converts any label references to addresses (whether absolute or relative).
| Can you take the address of main? |
Probably not according to the standard, but almost certainly in practice, although the compiler might warn you, and the optimiser is free to remove any undefined behaviour without issuing a warning.
Your definition of a function doesn't really make sense though. "Something you can take the address of" includes literally any object in a C++ program, and in functional languages, "Something that is callable" is ambiguous, because code and data are considered equal yet you wouldn't really talk about "callable data". Also, on a non-Von Neumann computer, it's possible that functions don't have addresses in the same way variables do. The Harvard architecture, for example, explicitly separates code and data. I don't think any Harvard architecture computers are actually in use but the standard is written with them in mind - that's why it says casting a function pointer to uintptr_t is undefined (although POSIX defines it, so a POSIX-compliant compiler will not remove that behaviour).
The mathematical definition of a function is something like "something that maps values from one set [the domain] to another [the range]" but that doesn't really apply to languages that aren't functionally pure, since they don't have to return values, and they can modify global state.
Generally, for non-functional languages, a function is something that's callable, and for a purely functional one, it's something that maps values from its domain to its range. main is callable, just not by you, so I would say it's a function.