[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [XForms] fdesign created c files, invalid conversion
From: |
Jens Thoms Toerring |
Subject: |
Re: [XForms] fdesign created c files, invalid conversion |
Date: |
Thu, 28 Oct 2010 22:52:35 +0200 |
User-agent: |
Mutt/1.5.20 (2009-06-14) |
Hi John,
On Thu, Oct 28, 2010 at 01:08:06PM -0700, John Wang wrote:
> I am using the currently latest version of xforms on a 64 bit ubuntu 10.10.
> Whenever I created a c file with fdesign, gcc will complain about invalid
> conversion from void* to FD_foo* at the line:
>
> FD_foo *fdui = fl_malloc( sizeof *fdui );
>
> to fix it, I will need to cast it properly like so:
>
> FD_foo *fdui = (FD_foo) fl_malloc( sizeof *fdui );
I guess you meant to use '(FD_foo*)' for the cast.
As far as I know without the cast it's correct standard C, so
I suspect that you're actually compiling with a C++ compiler
because C++ is more picky in this respect (it doesn't do the
automatic conversion from a void pointer to any other object
pointer). Is that the case?
> is there a way to avoid having to fix this manually everytime?
Unfortunately, not at the moment. I will change fdesign so
that the cast is automatically added to allow compilation
with C++ compilers (I took that out quite some time ago,
not considering that people might use C++ compilers, and
nobody complained until now;-). But that will only fix
things if you then use the new version to be uploaded.
I'm sorry for the inconvenience!
I will fix that ASAP and make a new release that outputs
files that get accepted by C++ compilers also.
Another fix would be to run a small script over the .c files
created by fdesign. Here's a Perl script that does that job
(hopefully, I just tested it with a single file):
---------------8<----------------------------------------
#!/usr/bin/perl
use warnings;
use strict;
open my $f, '<', $ARGV[ 0 ]
or die "Can't open $ARGV[ 0 ] for reading: $!\n";
my @lines;
push @lines, $_ for <$f>;
close $f;
open $f, '>', $ARGV[ 0 ]
or die "Can't open $ARGV[ 0 ] for writing: $!\n";
for ( @lines ) {
s/^\s+(FD_[a-z0-9_]+) \*fdui = (fl_malloc.+)$/ $1 *fdui = ($1*) $2/i;
print $f $_;
}
close $f;
---------------8<----------------------------------------
Pass it the name of the file you want to convert and the
casts should get added. (Please note: since it does in-place
replacement, i.e. overwrites the original file, you may want
to make a backup of the original file for the case that some-
thing goes wrong...)
Best regards, Jens
--
\ Jens Thoms Toerring ________ address@hidden
\_______________________________ http://toerring.de
Re: [XForms] fdesign created c files, invalid conversion, Rouben Rostamian, 2010/10/28