Hello all,
To start teh day, a small patch for an invalid local variable... In C, local variable must be declared before any statment, and not, like in C++ in the middle of the function.
Make good use of it.
Regards,
Stephan.
Signed-off-by: Stephan Guilloux stephan.guilloux@free.fr
diff -rc flashrom-623/physmap.c flashrom-623.new/physmap.c *** flashrom-623/physmap.c Tue Jun 23 07:28:15 2009 --- flashrom-623.new/physmap.c Tue Jun 23 09:46:01 2009 *************** *** 80,85 **** --- 80,87 ----
void *physmap(const char *descr, unsigned long phys_addr, size_t len) { + void *virt_addr; + if (len == 0) { printf_debug("Not mapping %s, zero size at 0x%08lx.\n", descr, phys_addr); *************** *** 96,102 **** descr, (unsigned long)len, phys_addr); }
! void *virt_addr = sys_physmap(phys_addr, len);
if (NULL == virt_addr) { if (NULL == descr) --- 98,104 ---- descr, (unsigned long)len, phys_addr); }
! virt_addr = sys_physmap(phys_addr, len);
if (NULL == virt_addr) { if (NULL == descr)
stephan.guilloux@free.fr wrote:
Hello all,
To start teh day, a small patch for an invalid local variable... In C, local variable must be declared before any statment, and not, like in C++ in the middle of the function.
Thanks a lot for the patch!
The restriction of local variable declarations only working at the top of the function has been revised in the C99 standard. Every compiler that is C99 compliant will understand the code and do the right thing.
Stefan
Selon Stefan Reinauer stepan@coresystems.de:
stephan.guilloux@free.fr wrote:
Hello all,
To start teh day, a small patch for an invalid local variable... In C, local variable must be declared before any statment, and not, like in
C++
in the middle of the function.
Thanks a lot for the patch!
No problem ;-)
The restriction of local variable declarations only working at the top of the function has been revised in the C99 standard. Every compiler that is C99 compliant will understand the code and do the right thing.
Unfortunatelly, all compiler are not C99 compliant, and this is also the only variable declared like this in flashrom.
Stephan
Stefan
-- coresystems GmbH ⢠Brahmsstr. 16 ⢠D-79104 Freiburg i. Br. Tel.: +49 761 7668825 ⢠Fax: +49 761 7664613 Email: info@coresystems.de ⢠http://www.coresystems.de/ Registergericht: Amtsgericht Freiburg ⢠HRB 7656 Geschäftsführer: Stefan Reinauer ⢠Ust-IdNr.: DE245674866
-- coreboot mailing list: coreboot@coreboot.org http://www.coreboot.org/mailman/listinfo/coreboot
stephan.guilloux@free.fr wrote:
Selon Stefan Reinauer stepan@coresystems.de:
stephan.guilloux@free.fr wrote:
Hello all,
To start teh day, a small patch for an invalid local variable... In C, local variable must be declared before any statment, and not, like in
C++
in the middle of the function.
Thanks a lot for the patch!
No problem ;-)
The restriction of local variable declarations only working at the top of the function has been revised in the C99 standard. Every compiler that is C99 compliant will understand the code and do the right thing.
Unfortunatelly, all compiler are not C99 compliant, and this is also the only variable declared like this in flashrom.
Interesting! Which compiler is this?
In this case we should definitely fix this..
Stefan
On 23.06.2009 12:32, Stefan Reinauer wrote:
stephan.guilloux@free.fr wrote:
To start teh day, a small patch for an invalid local variable... In C, local variable must be declared before any statment, and not, like in C++ in the middle of the function.
Thanks a lot for the patch!
The restriction of local variable declarations only working at the top of the function has been revised in the C99 standard. Every compiler that is C99 compliant will understand the code and do the right thing.
Still, on oddball platforms there may be no C99 compliant compilers. I tend to apply this patch, but I don't feel strongly about it.
Regards, Carl-Daniel
On Tue, Jun 23, 2009 at 12:32:05PM +0200, Stefan Reinauer wrote:
stephan.guilloux@free.fr wrote:
Hello all,
To start teh day, a small patch for an invalid local variable... In C, local variable must be declared before any statment, and not, like in C++ in the middle of the function.
Thanks a lot for the patch!
The restriction of local variable declarations only working at the top of the function has been revised in the C99 standard. Every compiler that is C99 compliant will understand the code and do the right thing.
Stefan
I personally dislike this, as it is only done to make it easier for people to be lazy.
By being forced to declare variables at the beginning of blocks, people are pushed towards creating smaller blocks and therefor expose natural deliniations quicker. Then people are more likely to create small (inlined) functions out of those blocks instead of using {} in the middle of a block.
Just because the compiler can handle it doesn't mean that you should write less good code than you could.
Let's keep variable declarations old style, as it is a style choice which has some consequences with respect to human behaviour.
Luc Verhaegen, A very lazy man who knows what he would be doing if things were made too easy on him.
Hi, Luc,
I agree we should set standards as low as possible, and try to make it easier for people to write good code, but..
On 23.06.2009 13:39 Uhr, Luc Verhaegen wrote:
I personally dislike this, as it is only done to make it easier for people to be lazy.
Or to make the code more compact and easier to read.
By being forced to declare variables at the beginning of blocks, people are pushed towards creating smaller blocks and therefor expose natural deliniations quicker.
While you may be right for many cases, I don't believe that cutting features of a programming language automatically makes people write better code. If it were, we'd all be writing firmware in Forth. ;-)
Just because the compiler can handle it doesn't mean that you should write less good code than you could.
Just because the compiler allows you to declare variables inline does not mean that you should create bigger code blocks or write worse code.
Stefan
On Tue, Jun 23, 2009 at 01:51:21PM +0200, Stefan Reinauer wrote:
Hi, Luc,
I agree we should set standards as low as possible, and try to make it easier for people to write good code, but..
On 23.06.2009 13:39 Uhr, Luc Verhaegen wrote:
I personally dislike this, as it is only done to make it easier for people to be lazy.
Or to make the code more compact and easier to read.
I believe that this one can go both ways. People can argue these both points from either side.
By being forced to declare variables at the beginning of blocks, people are pushed towards creating smaller blocks and therefor expose natural deliniations quicker.
While you may be right for many cases, I don't believe that cutting features of a programming language automatically makes people write better code. If it were, we'd all be writing firmware in Forth. ;-)
This is one of those things that i believe are not a feature, and is just something that c++ developers got used to and then claim they missed when they were back in the C world for a bit.
Just because the compiler can handle it doesn't mean that you should write less good code than you could.
Just because the compiler allows you to declare variables inline does not mean that you should create bigger code blocks or write worse code.
It is something that cannot be stopped. It is human nature and it will always happen. Not everybody is always as nitpicky when writing or reviewing code.
Luc Verhaegen.
Selon Luc Verhaegen libv@skynet.be:
On Tue, Jun 23, 2009 at 01:51:21PM +0200, Stefan Reinauer wrote:
Hi, Luc,
I agree we should set standards as low as possible, and try to make it easier for people to write good code, but..
On 23.06.2009 13:39 Uhr, Luc Verhaegen wrote:
I personally dislike this, as it is only done to make it easier for people to be lazy.
Or to make the code more compact and easier to read.
I believe that this one can go both ways. People can argue these both points from either side.
By being forced to declare variables at the beginning of blocks, people are pushed towards creating smaller blocks and therefor expose natural deliniations quicker.
While you may be right for many cases, I don't believe that cutting features of a programming language automatically makes people write better code. If it were, we'd all be writing firmware in Forth. ;-)
This is one of those things that i believe are not a feature, and is just something that c++ developers got used to and then claim they missed when they were back in the C world for a bit.
I agree with it. Why not adding a compiling option to have GCC in ANSI mode ?
Just because the compiler can handle it doesn't mean that you should write less good code than you could.
Just because the compiler allows you to declare variables inline does not mean that you should create bigger code blocks or write worse code.
It is something that cannot be stopped. It is human nature and it will always happen. Not everybody is always as nitpicky when writing or reviewing code.
Luc Verhaegen.
-- coreboot mailing list: coreboot@coreboot.org http://www.coreboot.org/mailman/listinfo/coreboot
IIRC this variable declaration in the middle of a code block has been an issue in the linux kernel as well, and variable declarations in the midst of code is not allowed.
It comes from C++. ANSI C++ allows it. I thought that ANSI C did too. Ah well.
ron
On 23.06.2009 10:42, stephan.guilloux@free.fr wrote:
To start teh day, a small patch for an invalid local variable... In C, local variable must be declared before any statment, and not, like in C++ in the middle of the function.
Signed-off-by: Stephan Guilloux stephan.guilloux@free.fr
Stefan committed this in r624.
Regards, Carl-Daniel