- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: With in C?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2001 10:12 AM
10-22-2001 10:12 AM
I'm in the middle of my big Pascal to C port and I have a problem. My original Pascal records contain many deeply nested records and variants. In Pascal it is very easy to address these field using the WITH statement. WITH w,x,y,z DO
BEGIN some assignments END. In C, the only thing I can do is make very long assignments. Is there an easier way?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2001 11:59 AM
10-22-2001 11:59 AM
SolutionAs I'm sure you are aware by now, C has no equivalent to Pascal's WITH. However, Standard Pascal has no equivalent to C's address operator and therein lies the method. You basically setup a point to a struct within your struct and then make the assignments using the pointer. Since I know this makes no sense, I'll attach a snippet of code.
Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2001 12:07 PM
10-22-2001 12:07 PM
Re: With in C?
Method B is to take advantage of the preprocessor and define a macro. Note the syntax of the macro WITH_C and especially the "\"'s to continue the macro. You might want to compile this snippet like this, cc -P dummy.c; this will simply preprocess the .c to produce a .i file (dummy.i). Examine the .i file to see how the macro was expanded. Also note, that I undef the macro as soon as I'm done so that another and possibly completely different WITH_C macro can be defined elsewhere. If is it a very common macro, you might include it in your header files so that many files can use it.
Regards and Happy C'ing, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2001 12:39 PM
10-22-2001 12:39 PM
Re: With in C?
I knew there had to be a way. Why did you declare your variables in a separate block? Couldn't I have I simply declared them at the top of the function?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2001 12:48 PM
10-22-2001 12:48 PM
Re: With in C?
In fact, I generally use block scope variables
in most cases and especially for counters and indices.
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2001 02:21 PM
10-22-2001 02:21 PM
Re: With in C?
One more question. In your example, if I have to assign values to both the b_recs and the c_recs within the a_rec, can I assign two pointers? Like this?
b_rec *bp = &(a.b);
c_rec *cp = &(bp->c);
bp->bi = 9;
cp->ci = 1;
Would that work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2001 02:30 PM
10-22-2001 02:30 PM
Re: With in C?
Once again, that normally should be with curly braces to make this stuff block scope. Also, the is no need to make long descriptive variables names like 'tmp_brec_pointer' or some such. The whole point is to make this shorthand - 'bp' is just fine. This is another reason to make the declarations block scope. They are always very near to the assignments and their meaning is then obvious and the 'disappear' when they have done their duty.
By the way, if you think the Pascal to C transition is fun, you will love the C to C++ transition. The learning curve is at least as steep.
Regards, Clay