| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Pascal - C |
sp> Hello? Anyone there? Hello?
Nope, we've all gone home.
sp> What's the closest one can get in C++, to Borland Pascal's enum/sets?
C enumerators are basically the same thing. But you can't declare an
enumerated variable in increment/decrement it over the list. You have to do
that manually, which is pretty much what Turbo Puke does anyway, only it is
'hidden' in your code.
Something like:
enum cartype =
{
volvo = 6,
citron = 8,
ford = 9,
holden = 12
};
enum cartype mytypes[] = { volvo, citron, ford, holden };
int i;
for (i = 0; i < (sizeof(mytypes)/sizeof(enum cartype)); i++)
{
enum cartype thistype = mytypes[i];
/* code */
}
Since you mention C++ specifically, and not C (yes, indeed there is a VAST
difference between the two even if C++ is an almost-superset of C), then
I'll also mention that if you define a class to emulate an enumerated type,
you can easily do the same 'hiding', and an overloaded operator++ and
operator--. Sets are trivial to implement in C++.
sp> And is it possible to do something like Pascal's nested procedures?
Not under either standard C or C++. However, some compiler implementations
such as Metaware's High-C, do have this (non-portable) feature.
The problem with introducing this into the general C/C++ climate is that
the benefits of a inherited/shared stack is not available or is difficult
to implement on many systems, or of little practical use when all is said
and done. In general, it is eaiser and simpler to use pointer-to-structs
anyway, and there's little, if any, loss of efficiency and an arguable gain
in code readability and maintainability.
BTW, you left the word "Borland" out before the word
"Pascal". Nested procedures is not a feature of ISO Pascal.
--- MaltEd/2 1.0.b6
* Origin: Unique Computing Pty Limited (3:632/348)SEEN-BY: 50/99 78/0 620/243 623/630 632/103 348 360 998 633/371 634/384 388 SEEN-BY: 634/396 635/301 502 503 544 639/252 711/401 409 410 413 430 808 809 SEEN-BY: 711/932 934 712/515 713/888 714/906 800/1 7877/2809 @PATH: 632/348 635/503 50/99 711/808 809 934 |
|
| 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™.