LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-02-2009, 08:25 AM   #1
navderm
Member
 
Registered: Dec 2008
Location: Chandigarh, India
Distribution: Red Hat 9
Posts: 67

Rep: Reputation: 15
Passing float values in FIFO


Hie Everyone,

I have been trying to pass the float values in FIFO but have not been able to do this. Probably because of some problems with the pointer.

Could you please help me do this.

Here is what I am trying to do:

I have two modules
1. Linux
2. RT Linux (i have started the function which allows the RT to use float point numbers)

Now
1st step : i transfer a float value from Linux to RT.
2nd step : i transfer the same value from RT to Linux.

The code should give me back the same no. in printing but it doesn't.

Any help would be greatly appreciated.
 
Old 01-02-2009, 11:38 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
Are you passing IEEE-754 format float values or pointers? You cannot use pointers to reference the same memory location from two separate processes.
 
Old 01-03-2009, 08:21 PM   #3
navderm
Member
 
Registered: Dec 2008
Location: Chandigarh, India
Distribution: Red Hat 9
Posts: 67

Original Poster
Rep: Reputation: 15
I do not think that is correct. I have sorted out the problem
The point is the computer cannot know whether the pointer is for a float or not unless it is told the same. So if i am supposed to pass a character pointer, it considers any pointer as character pointer. Hence if i first pass a float pointer with a typecast of character. i accepts. Now if i convert the same pointer (or say accept this pointer) in other program with a float type cast, it works fine. I have the code, if you need it,jim.

thx
 
Old 01-04-2009, 03:00 PM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Code:
float my_value = 0.0;

//...

write(fd, &my_value, sizeof my_value);

//...

read(fd, &my_value, sizeof my_value);
That really isn't a good idea unless you know this will always happen on the same machine, so normally I convert numbers to text before sending them. There normally isn't much of a point sending values in their binary formats unless you're sending precisely-aligned data structures with exacting binary information; a category that floating points don't fall into. You won't lose much converting to and from a string with *printf and strto*. And unless you're sending strictly a single type and nothing else, you'll need some sort of alignment control (which is usually done with a simple text protocol) to prevent a minor error from corrupting all subsequent IPC.
ta0kira

Last edited by ta0kira; 01-04-2009 at 03:07 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
reading integer values from excel using java - interprets it as float kshkid Programming 3 07-28-2008 12:53 AM
perl - passing values to subroutines sporty Programming 7 08-08-2006 09:13 AM
Passing form values between multiple forms!! AskMe Programming 5 09-07-2005 07:44 PM
Sed Command & Passing Values joey52 Linux - Newbie 4 12-27-2004 07:46 PM
passing values in shell pantera Programming 1 05-20-2004 09:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration