Re: [fpc-devel] void test( void *data ) to procedure test( var data); ? is it safe ?

2011-06-21 Thread Hans-Peter Diettrich

Skybuck Flying schrieb:

Passing real pointers and working with them becomes even more tricky and 
requires even more stars/asterixes.


A very bad problem which was easily solved in pascal:

procedure test( var a : integer );
begin
 a := 5;
end;

test( a );

^ No stupid symbols needed ! ;) Much user friendly and pretty much does 
the same thing.


Why make things more difficult then absolutely necessary huh ?! ;) :) =D


What does above code when called with Nil?

While
  test(nil);
may result in a compiler error, the only cure would be to rewrite test as
  procedure test(a: ^integer);

But how would you do that, when the converter decided to use
  procedure test(var a: integer);
instead?

You'll have to *instruct* the converter to use the pointer form, and 
that for *every single* subroutine in the C code.


A converter also cannot determine from a header file, whether the 
implementation does something like this:


int test(int* a)
{
  return (a)?++*a:42;
}

DoDi

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] void test( void *data ) to procedure test( var data); ? is it safe ?

2011-06-21 Thread Skybuck Flying

The difference is actually:

1. Pascal has call by value and call by reference.
2. C only has call by value.

Because of limitation 2, C programmers use the pointer trick to pass the 
address of a variable so it can be changed inside the routine, example:


1. C call by value (default):

void test( int a )
{
 a = 5; // after routine exists, value is lost.
}

test( b );

2. C call by value (reference trick):

void test( int *a ) <- pointer to variable of integer trick.
{
 *a = 5;
}

test( &b ); // <- address of variable trick.

For noobies/novice programmers this makes C a bad language since 
noobies/novice programmers are still learning to design software codes and 
will often need to change call by value to call by reference or vice versa 
and then it becomes a hurdle to change all these call sites, not mention 
confusion.


For experienced programmers it's also a reall burden to use * everywhere and 
& everywhere, everywhere reference comes into play.


Passing real pointers and working with them becomes even more tricky and 
requires even more stars/asterixes.


A very bad problem which was easily solved in pascal:

procedure test( var a : integer );
begin
 a := 5;
end;

test( a );

^ No stupid symbols needed ! ;) Much user friendly and pretty much does the 
same thing.


Why make things more difficult then absolutely necessary huh ?! ;) :) =D

Only thing I can imagine is very very very maybe it's easier to write a 
"call by value compiler" than a "call by reference compiler" ?!? But does 
sound a bit like bullshit to me ?! ;) :)


Bye,
 Skybuck =D 


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: RE : [fpc-devel] void test( void *data ) to procedure test( var data ); ? is it safe ?

2011-06-21 Thread Michael Schnell

On 06/20/2011 07:43 PM, Hans-Peter Diettrich wrote:
A C compiler should report an syntax error, but Microsoft C/C++ is 
something different from C and C++ standards :-(



Typical for M$ :(

I just did a small java script program and this did now work correctly 
in InternetExplorer. I found that according to the JavaScript docs I 
found date.Year is based on 1900 and Firefox does work this way, while 
with IE date.Year is based on 0.


-Michael
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: RE : [fpc-devel] void test( void *data ) to procedure test( var data ); ? is it safe ?

2011-06-20 Thread Hans-Peter Diettrich

Michael Schnell schrieb:

On 06/20/2011 09:55 AM, Ludo Brands wrote:

Prototypes for routines:

1: void test(void *data)
2: void test(void&data)
IMHO a "&" in a function prototype definition in C is conceptional 
nonsense.


A C compiler should report an syntax error, but Microsoft C/C++ is 
something different from C and C++ standards :-(


DoDi

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: RE : [fpc-devel] void test( void *data ) to procedure test( var data ); ? is it safe ?

2011-06-20 Thread Marco van de Voort
In our previous episode, Ludo Brands said:
> 1: void test(void *data)
> 2: void test(void &data)
> 
> The first one does compile in visual studio 2010 and the second does not.

The first is C and C++, the second might be C++ only. (& is also used for
smartpointer related stuff in C++)

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: RE : [fpc-devel] void test( void *data ) to procedure test( var data ); ? is it safe ?

2011-06-20 Thread Michael Schnell

On 06/20/2011 09:55 AM, Ludo Brands wrote:

Prototypes for routines:

1: void test(void *data)
2: void test(void&data)
IMHO a "&" in a function prototype definition in C is conceptional 
nonsense.


-Michael
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


RE : [fpc-devel] void test( void *data ) to procedure test( var data ); ? is it safe ?

2011-06-20 Thread Ludo Brands

An "in depth" discussion of the subject can be found here:
http://www.velocityreviews.com/forums/t750137-test-void-data-vs-test-void-an
d-data.html



-Message d'origine-
De : fpc-devel-boun...@lists.freepascal.org
[mailto:fpc-devel-boun...@lists.freepascal.org] De la part de Skybuck Flying
Envoyé : samedi 18 juin 2011 22:44
À : FPC developers' list
Objet : [fpc-devel] void test( void *data ) to procedure test( var data );?
is it safe ?
Prototypes for routines:

1: void test(void *data)
2: void test(void &data)

The first one does compile in visual studio 2010 and the second does not.

They both seem conceptually the same, like untyped variable data in Delphi, 
yet the first one is allowed and the second is not allowed.

Isn't that strange ?! ;) :)

Seems like case 2 is not yet implemented, either in the c/c++ language rules

or in the compiler ?! ;)

Bye,
  Skybuck.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] void test( void *data ) to procedure test( var data ); ? is it safe ?

2011-06-19 Thread Hans-Peter Diettrich

Skybuck Flying schrieb:


So now I am wondering if it's safe to convert:
 
void test( void *data )
 
to
 
procedure test( var data );


AFAIR this can cause problems, when the C code tests "data" for NULL.


I don't want no strange stack problems or access violations or anything 
like that, so I have to make sure it's 100% the same and safe ?!?


The safe way is using pointer types in OPL, for C "*" parameters.


The convenience would be nice to have though...
 
My thoughts on the c/c++ inconsistency:
 
Prototypes for routines:
 
1: void test(void *data)

2: void test(void &data)
 
The first one does compile in visual studio 2010 and the second does not.


Right. C++ "&" references never can be void or NULL, while C "*" and 
Delphi "var" (by-ref) parameters can be untyped and Nil. That's one of 
the subtle differences between C++ and OPL, which should be handled 
properly by every converter.


DoDi

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


[fpc-devel] void test( void *data ) to procedure test( var data ); ? is it safe ?

2011-06-19 Thread Skybuck Flying
I had to convert "void test( void *data)" to Delphi/Pascal.

My first conversion was:

procedure test( data : pointer );

The documentation of the test function seems to indicate that this function 
returns all kinds of pointers, so it's like a call by reference call.

So I am starting to wonder if I perhaps should change it to something more 
convenient like:

procedure test( var data );

I was trying out c/c++ to see if void test( void &data ) would be valid/legal 
but to my surprise it was not (visual studio 2010).

So now I am wondering if it's safe to convert:

void test( void *data ) 

to

procedure test( var data );

I don't want no strange stack problems or access violations or anything like 
that, so I have to make sure it's 100% the same and safe ?!?

The convenience would be nice to have though...

My thoughts on the c/c++ inconsistency:

Prototypes for routines:

1: void test(void *data)
2: void test(void &data)

The first one does compile in visual studio 2010 and the second does not.

They both seem conceptually the same, like untyped variable data in Delphi, 
yet the first one is allowed and the second is not allowed.

Isn't that strange ?! ;) :)

Seems like case 2 is not yet implemented, either in the c/c++ language rules 
or in the compiler ?! ;)

Bye,
  Skybuck.___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel