| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Auto string-length determination |
PW> I tried to automatically determine the maximum string length by using : PW> int Max_Length = sizeof(String) / sizeof(char); PE> BTW, as far as I'm aware, you're meant to go "sizeof String" for a PE> variable, and "sizeof(char)" for a data type. PW> "sizeof String" ??? Are you SURE??? No one else has pointed that out! No one else would call you a Borland Fan if you went "void main" either, doesn't say much. ISO 6.3.3.4 The sizeof operator yields the size (in bytes) of its operand, which may be an expression or the parenthesized name of a type. They give examples... sizeof *dp sizeof array / sizeof array[0] Now, as far as I am aware, an "expression" would include putting the variable in parentheses, e.g. x and (x) should both be valid expressions. Is there are circumstance where x would work, but (x) wouldn't? Not that comes to mind. What about the reverse? Might putting x in parentheses be better, to make sure that you know which expression the sizeof is being done against? Possibly. If I come to a situation where it is potentially ambiguous, I might experiment. Until then, for the simple cases, I'll just do as they said above. At least for the same reason that I don't go x = (y) * (4). BFN. Paul. @EOT: ---* Origin: X (3:711/934.9) SEEN-BY: 633/267 270 @PATH: 711/934 808 50/99 635/544 727 728 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.