4 ms·
Maybe I'm missing something, but I think Pascal "TYPE" blocks and C "typedef" statements do pretty much the same thing. (they don't look the same, but you can
by Roboprog 10y ago
Maybe I'm missing something, but I think Pascal "TYPE" blocks and C "typedef" statements do pretty much the same thing.
(they don't look the same, but you can use either to define record/structure types or enums, for example)
- barrkel 10y agoThe distinction is in the syntax. int main() { foo(bar); foo * bar; } If foo is a typedef, these are variable declarations, otherwise the first is a function call and the second multiplication (syntactically). These are different kinds of things that would normally be up to the parser to figure out (rather than semantic analysis later). These are well-known ambiguities relating to typedefs in C (well-known to compiler authors, at any rate). The situation doesn't come up in Pascal because variables go in the var block (starting with the 'var' keyword) and functions and procedures both start with keywords ('function' and 'procedure').
- Roboprog 10y agoOK, thanks. I was focusing on the "definition" part, rather than the "usage" part of the types. It never occurred to me to put variables names inside parens in a declaration when I did C, though. But OF COURSE it's legal obfuscation. As stated elsewhere, I don't know why C had to screw up Algol's syntax so badly. I guess K&R liked curly braces much more than BEGIN/END, and why stop there, once you get going. Maybe somebody had a love affair with APL???