The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 3-byte integers?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Mike Buess

USA
3037 Posts

Posted - 03/12/2003 :  3:14:49 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Is it possible to read 3-byte integers from file in Origin C? ReadInt(dd, 3, nInts) or Read(&dd, sizeof(dd)) don't work because there are no 3-byte integer types to use for dd. Is there a way around this?

Mike Buess
Origin WebRing Member

dlw21

USA
18 Posts

Posted - 03/13/2003 :  09:33:18 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Mike,

When I've had non-standard words to read in the past, I've usually done it (on unix platforms) with something like this:

 
char buffer[4] = { \000, \000, \000, \000 };
int result, nread;
nread = read(fd,buffer,3);
if ( nread > 0 ) result = *((int *)buffer);


Note that the key is explicitly asking for the number of bytes, not relying on a built-in type.

If the platform that wrote the data is different from the platform reading it, you may have to be careful to byte-swap "result" once it has the data in it.

I haven't tried the above code in OriginC, so I don't know if it would work. If not, surely you could get it to work as an external DLL (though I am not sure what the VC++ equivalent of read() is).

Good luck with this problem!
Dave


Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 03/13/2003 :  5:25:46 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks, Dave. I may try that. The thing is that Origin's File Utility Module (FUM) handles 3-byte integers just fine. I've obtained some performance gains by rewriting other of my LabTalk routines in OriginC, so I thought I'd try with this one. But perhaps this in an area where I should just leave well enough alone.
quote:
If the platform that wrote the data is different from the platform reading it, you may have to be careful to byte-swap "result" once it has the data in it.
Unfortunately, most of the files I deal with are written on non-Windows platforms (Unix, MacIntosh) so byte-order is a familiar issue.

Thanks again,

Mike Buess
Origin WebRing Member
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000