Is anyone planning to rewrite precompile.pike within the near future? If not, I will probably add some code to the current version tonight which will allow variable definitions anywhere within the code. The idea is to locate all definitions of variables and move them to the top.
Example:
int x=0; int y=1; for(int i=x;i<y;i++) ...;
will become
int x=0; int y=1; int i; for(i=x;i<y;i++) ...;
Come again?
/ Peter Bortas (Kein Paket!)
Previous text:
2004-05-05 10:18: Subject: precompile.pike
Is anyone planning to rewrite precompile.pike within the near future? If not, I will probably add some code to the current version tonight which will allow variable definitions anywhere within the code. The idea is to locate all definitions of variables and move them to the top.
Example:
int x=0; int y=1; for(int i=x;i<y;i++) ...;
will become
int x=0; int y=1; int i; for(i=x;i<y;i++) ...;
/ Marcus Agehall (Scanian)
Avoid problems with compilers that wants all variables defined before the code in a function. When Nilsson and wrote the new C-based hash-methods for the Crypto module, I accidently put a variable definition in the middle of the code. GCC didn't complain but some other platforms did.
Instead of learning C better, I developed code that solves the problem... ;)
/ Marcus Agehall (Scanian)
Previous text:
2004-05-05 10:21: Subject: precompile.pike
Come again?
/ Peter Bortas (Kein Paket!)
Aah. it's just the .cmod code. Then I get it...
/ Mirar
Previous text:
2004-05-05 10:31: Subject: precompile.pike
Avoid problems with compilers that wants all variables defined before the code in a function. When Nilsson and wrote the new C-based hash-methods for the Crypto module, I accidently put a variable definition in the middle of the code. GCC didn't complain but some other platforms did.
Instead of learning C better, I developed code that solves the problem... ;)
/ Marcus Agehall (Scanian)
All C-compilers pre C99 and gcc-extensions would complain. I'm not all that enthusiatic about new methods of hiding errors in layers of precompilation.
/ Peter Bortas (Kein Paket!)
Previous text:
2004-05-05 10:31: Subject: precompile.pike
Avoid problems with compilers that wants all variables defined before the code in a function. When Nilsson and wrote the new C-based hash-methods for the Crypto module, I accidently put a variable definition in the middle of the code. GCC didn't complain but some other platforms did.
Instead of learning C better, I developed code that solves the problem... ;)
/ Marcus Agehall (Scanian)
In fact, it could very well create seroius and hard to debug errors. You are transfering variables from local to global scope.
/ Peter Bortas (Kein Paket!)
Previous text:
2004-05-05 10:34: Subject: precompile.pike
All C-compilers pre C99 and gcc-extensions would complain. I'm not all that enthusiatic about new methods of hiding errors in layers of precompilation.
/ Peter Bortas (Kein Paket!)
How do those compilers want their variables defined then?
/ Marcus Agehall (Scanian)
Previous text:
2004-05-05 10:34: Subject: precompile.pike
All C-compilers pre C99 and gcc-extensions would complain. I'm not all that enthusiatic about new methods of hiding errors in layers of precompilation.
/ Peter Bortas (Kein Paket!)
Ah, perhaps I'm very unclear on this point. I wish to do the following:
void f() { for(int x=0;;) ...; }
=>
void f() { int x; for(x=0;;) ...; }
ie, variables shouldn't become global, just moved within the function.
/ Marcus Agehall (Scanian)
Previous text:
2004-05-05 11:18: Subject: precompile.pike
In the beginning of each scope. IE, after any "{".
/ Peter Bortas (Kein Paket!)
Learn C.
It would still be likely to introduce bugs.
/ Henrik Grubbström (Lysator)
Previous text:
2004-05-05 11:25: Subject: precompile.pike
Ah, perhaps I'm very unclear on this point. I wish to do the following:
void f() { for(int x=0;;) ...; }
=>
void f() { int x; for(x=0;;) ...; }
ie, variables shouldn't become global, just moved within the function.
/ Marcus Agehall (Scanian)
Trying hard not to.. ;)
The biggest problem IMHO is that things may work just fine on my GCC but might fail on plenty of other platforms. I want to introduce something that prevents this from happening. If you have some better suggestions as how to solve that problem, I'm interested.
/ Marcus Agehall (Scanian)
Previous text:
2004-05-05 11:27: Subject: precompile.pike
Learn C.
It would still be likely to introduce bugs.
/ Henrik Grubbström (Lysator)
Learn C.
/ Per Hedbor ()
Previous text:
2004-05-05 12:08: Subject: precompile.pike
Trying hard not to.. ;)
The biggest problem IMHO is that things may work just fine on my GCC but might fail on plenty of other platforms. I want to introduce something that prevents this from happening. If you have some better suggestions as how to solve that problem, I'm interested.
/ Marcus Agehall (Scanian)
There are not that many differences between C89 and C99/gcc in normal day use. You have just learned the most common one.
/ Peter Bortas (Kein Paket!)
Previous text:
2004-05-05 12:08: Subject: precompile.pike
Trying hard not to.. ;)
The biggest problem IMHO is that things may work just fine on my GCC but might fail on plenty of other platforms. I want to introduce something that prevents this from happening. If you have some better suggestions as how to solve that problem, I'm interested.
/ Marcus Agehall (Scanian)
Is it possible to have GCC warn me of these things? That could be an acceptable solution.
/ Marcus Agehall (Scanian)
Previous text:
2004-05-05 12:29: Subject: precompile.pike
There are not that many differences between C89 and C99/gcc in normal day use. You have just learned the most common one.
/ Peter Bortas (Kein Paket!)
That problem can be easily solved with the flags "-pedantic -Werror".
/ Marcus Comstedt (ACROSS) (Hail Ilpalazzo!)
Previous text:
2004-05-05 12:08: Subject: precompile.pike
Trying hard not to.. ;)
The biggest problem IMHO is that things may work just fine on my GCC but might fail on plenty of other platforms. I want to introduce something that prevents this from happening. If you have some better suggestions as how to solve that problem, I'm interested.
/ Marcus Agehall (Scanian)
You have to add a new scope too. Consider for(int i=-10;i<10;i++); for(unsigned int i=0;i<10;i++);
And I fail to see the point, really.
/ Per Hedbor ()
Previous text:
2004-05-05 11:25: Subject: precompile.pike
Ah, perhaps I'm very unclear on this point. I wish to do the following:
void f() { for(int x=0;;) ...; }
=>
void f() { int x; for(x=0;;) ...; }
ie, variables shouldn't become global, just moved within the function.
/ Marcus Agehall (Scanian)
What does this affect? Code that is compiled with precompile.pike?
/ Mirar
Previous text:
2004-05-05 10:18: Subject: precompile.pike
Is anyone planning to rewrite precompile.pike within the near future? If not, I will probably add some code to the current version tonight which will allow variable definitions anywhere within the code. The idea is to locate all definitions of variables and move them to the top.
Example:
int x=0; int y=1; for(int i=x;i<y;i++) ...;
will become
int x=0; int y=1; int i; for(i=x;i<y;i++) ...;
/ Marcus Agehall (Scanian)
No.
for(int x=0;;)
will become
int x; for(x=0;;)
As far as I know, that should not break things.
/ Marcus Agehall (Scanian)
Previous text:
2004-05-05 10:29: Subject: precompile.pike
That means that code today that uses for instance
{ .... for (int i=...;;) ... for (float i=...;;) ... }
will break?
/ Mirar
You could make it to
{ int x; for(x=0;;) }
instead, which is allowed in most older C compilers too (I think -- at least Pike uses it in a lot of macros).
This will disallow (broken(?)) use of x after the for scope.
/ Mirar
Previous text:
2004-05-05 10:32: Subject: precompile.pike
No.
for(int x=0;;)
will become
int x; for(x=0;;)
As far as I know, that should not break things.
/ Marcus Agehall (Scanian)
Yes, for those cases that might be possible. I was not aware that such constructions were allowed. But one still needs to move variables defined in the code like:
... int x = 10; ...
should be
int x; ... x=10; ...
since it's not known where x is used after the definition.
/ Marcus Agehall (Scanian)
Previous text:
2004-05-05 10:34: Subject: precompile.pike
You could make it to
{ int x; for(x=0;;) }
instead, which is allowed in most older C compilers too (I think -- at least Pike uses it in a lot of macros).
This will disallow (broken(?)) use of x after the for scope.
/ Mirar
Yes, then you need to move it to the top of the scope, or create a new scope for x until the end of the current scope:
{
... int x = 10; ...
}
->
{ ... { int x=10; ... } }
/ Mirar
Previous text:
2004-05-05 10:42: Subject: precompile.pike
Yes, for those cases that might be possible. I was not aware that such constructions were allowed. But one still needs to move variables defined in the code like:
... int x = 10; ...
should be
int x; ... x=10; ...
since it's not known where x is used after the definition.
/ Marcus Agehall (Scanian)
Why? Seems likely to introduce bugs.
/ Henrik Grubbström (Lysator)
Previous text:
2004-05-05 10:18: Subject: precompile.pike
Is anyone planning to rewrite precompile.pike within the near future? If not, I will probably add some code to the current version tonight which will allow variable definitions anywhere within the code. The idea is to locate all definitions of variables and move them to the top.
Example:
int x=0; int y=1; for(int i=x;i<y;i++) ...;
will become
int x=0; int y=1; int i; for(i=x;i<y;i++) ...;
/ Marcus Agehall (Scanian)
pike-devel@lists.lysator.liu.se