Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #109486

Re: obtaining a c value from a perl script

From fred flintstone <fred@server.invalid>
Newsgroups comp.lang.c
Subject Re: obtaining a c value from a perl script
Date 2017-05-08 03:52 -0700
Message-ID <enb0v4FrgpnU1@mid.individual.net> (permalink)
References <emm0h5Foml1U1@mid.individual.net> <874lx6hqng.fsf@bsb.me.uk> <emojs3F9fp8U1@mid.individual.net> <oefke2$ktn$1@gioia.aioe.org>

Show all headers | View raw


On 05/04/2017 09:21 AM, Manfred wrote:

[OP now doubts what he thought he knew about C doubles]

>> Let's say I had a value in perl that I knew was a c double. It's a
>> premise.
>>
>> If the only output of this script were:
>>
>> say "$equal";
>>
>> , then I think there is a wide road for C interop.
>
> I may point out the two easiest answers here, sure others may tell more
> and/or correct me:
>
> 1) using program arguments is not shameful, they are there for a
> purpose, so if you have your variables to feed to a C program, you can
> use command line arguments for the task. Besides data size, one relevant
> constraint here is that program arguments must be passed in a /textual/
> representation.
> So the type of your parameters becomes relevant for the choice. Floating
> point doubles can in principle be passed converted as text as long as
> you ensure sufficient precision.
> (if the doubles are an encoding of date/times, as in some Windows data
> types, it would probably be better to convert them in a more suitable
> format)

Thanks, manfred, your reply made me not distrust the way you get the 
ball rolling in C:

https://github.com/TBlazer66/gcc/blob/master/1.receive.c

I use this script to drive the process:

https://github.com/TBlazer66/gcc/blob/master/5.toolchain.sh

But is that the only fig leaf we need? Well no, as per your reply. I 
seem to be a bit rusty. Indeed, I found a post about how everything I 
used to know about how to print a double just went back to %f. Anyways, 
here was my attempt to write legal, contemporary C (cringe):

#include <stdio.h>

int main (int argc, char *argv[])
{
   int count;
   double d;

   printf ("This program was called with \"%s\".\n",argv[0]);

   if (argc = 2)
     {
        d = (double) argv[1];
        printf("Value from perl : %f\n", d );
     }
   else
     {
       printf("The program was called wrong.\n");
     }

   return 0;
}

gcc s


   if (argc > 1)
     {
       for (count = 1; count < argc; count++)
	{
	  printf("argv[%d] = %s\n", count, argv[count]);
	}
     }
   else
     {
       printf("The command had no other arguments.\n");
     }

   return 0;
}


I don't understand the first error, which is reason enough for me not to 
have to wonder why there more:

$ create.sh 1.receive.c
1
2
2.receive.c
substitute 2 into output files
$ sh 6.toolchain.sh
2.receive.c: In function ‘main’:
2.receive.c:10:3: warning: suggest parentheses around assignment used as 
truth value [-Wparentheses]
    if (argc = 1)
    ^
2.receive.c:12:8: error: pointer value used where a floating point value 
was expected
         d = (double) argv[1];
         ^
2.receive.c:5:7: warning: unused variable ‘count’ [-Wunused-variable]
    int count;
        ^
$ sh 6.toolchain.sh
2.receive.c: In function ‘main’:
2.receive.c:10:3: warning: suggest parentheses around assignment used as 
truth value [-Wparentheses]
    if (argc = 2)
    ^
2.receive.c:12:8: error: pointer value used where a floating point value 
was expected
         d = (double) argv[1];
         ^
2.receive.c:5:7: warning: unused variable ‘count’ [-Wunused-variable]
    int count;
        ^
$
>
> 2) The second easiest input is via input stream (stdin). In this case
> you have to establish a common data format between your output and the C
> program (it may be noted that C streams are raw sequences of bytes, you
> have to specify all details of its format).
> This does also allow for binary data transfer (which I do not know how
> Perl can deal with), in which case you have to ensure proper format
> (endianness, size, etc) of data, like e.g IEEE 754 (now IEC 60559) for
> floating point values.

That's not the direction this is heading. I need to have that legal C 
value before I want to show anybody what that value is.

If I'm tormenting this newsgroup by my very presence, just give me what 
I want, and no one gets hurt....
-- 
fred

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

obtaining a c value from a perl script fred flintstone <fred@server.invalid> - 2017-04-30 04:36 -0700
  Re: obtaining a c value from a perl script Noob <root@127.0.0.1> - 2017-04-30 14:48 +0200
    Re: obtaining a c value from a perl script fred flintstone <fred@server.invalid> - 2017-05-01 02:25 -0700
      Re: obtaining a c value from a perl script Keith Thompson <kst-u@mib.org> - 2017-05-01 08:46 -0700
        Re: obtaining a c value from a perl script fred flintstone <fred@server.invalid> - 2017-05-03 02:12 -0700
          Re: obtaining a c value from a perl script Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-05-03 11:48 +0100
  Re: obtaining a c value from a perl script Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-04-30 16:16 +0100
    Re: obtaining a c value from a perl script fred flintstone <fred@server.invalid> - 2017-05-01 04:18 -0700
      Re: obtaining a c value from a perl script Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-05-01 13:41 +0100
        Re: obtaining a c value from a perl script Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2017-05-03 05:10 -0700
          Re: obtaining a c value from a perl script Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-05-03 15:00 +0100
          Re: obtaining a c value from a perl script Keith Thompson <kst-u@mib.org> - 2017-05-03 08:55 -0700
            Re: obtaining a c value from a perl script Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2017-05-03 09:02 -0700
              Re: obtaining a c value from a perl script Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-05-03 17:22 +0100
                Re: obtaining a c value from a perl script fred flintstone <fred@server.invalid> - 2017-05-08 01:43 -0700
                Re: obtaining a c value from a perl script Keith Thompson <kst-u@mib.org> - 2017-05-08 09:06 -0700
                Re: obtaining a c value from a perl script fred flintstone <fred@server.invalid> - 2017-05-09 00:35 -0700
                Re: obtaining a c value from a perl script David Brown <david.brown@hesbynett.no> - 2017-05-09 13:59 +0200
              Re: obtaining a c value from a perl script fred flintstone <fred@server.invalid> - 2017-05-08 02:45 -0700
                Re: obtaining a c value from a perl script Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2017-05-08 04:39 -0700
                solved Re: obtaining a c value from a perl script fred flintstone <fred@server.invalid> - 2017-05-09 02:43 -0700
                Re: solved Re: obtaining a c value from a perl script Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-05-09 15:06 +0100
                Re: solved Re: obtaining a c value from a perl script fred flintstone <fred@server.invalid> - 2017-05-10 01:03 -0700
                Re: solved Re: obtaining a c value from a perl script Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-05-10 11:18 +0100
                Re: solved Re: obtaining a c value from a perl script fred flintstone <fred@server.invalid> - 2017-05-12 02:26 -0700
                Re: solved Re: obtaining a c value from a perl script Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-05-12 11:51 +0100
                Re: solved Re: obtaining a c value from a perl script fred flintstone <fred@server.invalid> - 2017-05-12 03:49 -0700
                Re: solved Re: obtaining a c value from a perl script Manfred <invalid@invalid.add> - 2017-05-10 23:21 +0200
                Re: solved Re: obtaining a c value from a perl script Keith Thompson <kst-u@mib.org> - 2017-05-10 16:23 -0700
                Re: solved Re: obtaining a c value from a perl script Robert Wessel <robertwessel2@yahoo.com> - 2017-05-11 15:57 -0500
                Re: solved Re: obtaining a c value from a perl script Jerry Stuckle <jstucklex@attglobal.net> - 2017-05-11 18:57 -0400
                Re: solved Re: obtaining a c value from a perl script Robert Wessel <robertwessel2@yahoo.com> - 2017-05-11 18:38 -0500
                Re: solved Re: obtaining a c value from a perl script Robert Wessel <robertwessel2@yahoo.com> - 2017-05-11 18:46 -0500
                Re: solved Re: obtaining a c value from a perl script Jerry Stuckle <jstucklex@attglobal.net> - 2017-05-11 21:11 -0400
                Re: solved Re: obtaining a c value from a perl script Robert Wessel <robertwessel2@yahoo.com> - 2017-05-12 01:51 -0500
                Re: solved Re: obtaining a c value from a perl script Jerry Stuckle <jstucklex@attglobal.net> - 2017-05-14 23:49 -0400
                Re: obtaining a c value from a perl script Tim Rentsch <txr@alumni.caltech.edu> - 2017-05-09 07:46 -0700
            Re: obtaining a c value from a perl script mark.bluemel@gmail.com - 2017-05-03 09:06 -0700
              Re: obtaining a c value from a perl script gazelle@shell.xmission.com (Kenny McCormack) - 2017-05-03 17:02 +0000
              Re: obtaining a c value from a perl script fred flintstone <fred@server.invalid> - 2017-05-08 01:51 -0700
      Re: obtaining a c value from a perl script Manfred <noname@invalid.add> - 2017-05-04 18:21 +0200
        Re: obtaining a c value from a perl script fred flintstone <fred@server.invalid> - 2017-05-08 03:52 -0700
          Re: obtaining a c value from a perl script Jerry Stuckle <jstucklex@attglobal.net> - 2017-05-08 08:38 -0400
          Re: obtaining a c value from a perl script Keith Thompson <kst-u@mib.org> - 2017-05-08 09:14 -0700
          Re: obtaining a c value from a perl script "James R. Kuyper" <jameskuyper@verizon.net> - 2017-05-08 12:17 -0400
            Re: obtaining a c value from a perl script Keith Thompson <kst-u@mib.org> - 2017-05-08 09:26 -0700
              Re: obtaining a c value from a perl script jameskuyper@verizon.net - 2017-05-08 11:02 -0700
                Re: obtaining a c value from a perl script Keith Thompson <kst-u@mib.org> - 2017-05-08 11:39 -0700
              Re: obtaining a c value from a perl script Tim Rentsch <txr@alumni.caltech.edu> - 2017-05-09 07:16 -0700
                Re: obtaining a c value from a perl script Keith Thompson <kst-u@mib.org> - 2017-05-09 08:18 -0700
                Re: obtaining a c value from a perl script fred flintstone <fred@server.invalid> - 2017-05-10 00:29 -0700
                Re: obtaining a c value from a perl script Tim Rentsch <txr@alumni.caltech.edu> - 2017-05-10 05:26 -0700
            Re: obtaining a c value from a perl script Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-05-08 18:20 +0100

csiph-web