On 07.10.2010 00:25, Idwer Vollering wrote:
2010/10/7 Uwe Hermann uwe@hermann-uwe.de
flashrom.c:1351: error: ‘for’ loop initial declarations are only allowed in C99 mode flashrom.c:1351: note: use option -std=c99 or -std=gnu99 to compile your code make: *** [flashrom.o] Error 1
I think this is the culprit:
for (int i = 0; i < startcol; i++) printf(" ");
Moving the "int i;" to the top of the function should fix it.
I think this is a better fix than this:
Index: Makefile
--- Makefile (revision 1196) +++ Makefile (working copy) @@ -26,7 +26,7 @@ DIFF = diff PREFIX ?= /usr/local MANDIR ?= $(PREFIX)/share/man -CFLAGS ?= -Os -Wall -Wshadow +CFLAGS ?= -Os -Wall -Wshadow -std=c99 EXPORTDIR ?= .
WARNERROR ?= yes
The above, with the patch in question applied, results in this error:
cc1: warnings being treated as errors flashrom.c: In function ‘doit’: flashrom.c:1596: error: implicit declaration of function ‘fileno’
Mh yes, once you switch the mode from gnu99 to c99, you get all sorts of pretty explosions. The following patch allows compilation with -std=c99 on my Linux box with gcc and clang, but I fear it will cause all sorts of funnies on other operating systems, and especially break on Windows.
This patch is for testing on non-Linux architectures, and _not_ for immediate merge.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: flashrom-c99_clean/hwaccess.h =================================================================== --- flashrom-c99_clean/hwaccess.h (revision 1199) +++ flashrom-c99_clean/hwaccess.h (working copy) @@ -256,37 +256,37 @@
static inline void outb(uint8_t value, uint16_t port) { - asm volatile ("outb %b0,%w1": :"a" (value), "Nd" (port)); + __asm__ volatile ("outb %b0,%w1": :"a" (value), "Nd" (port)); }
static inline uint8_t inb(uint16_t port) { uint8_t value; - asm volatile ("inb %w1,%0":"=a" (value):"Nd" (port)); + __asm__ volatile ("inb %w1,%0":"=a" (value):"Nd" (port)); return value; }
static inline void outw(uint16_t value, uint16_t port) { - asm volatile ("outw %w0,%w1": :"a" (value), "Nd" (port)); + __asm__ volatile ("outw %w0,%w1": :"a" (value), "Nd" (port)); }
static inline uint16_t inw(uint16_t port) { uint16_t value; - asm volatile ("inw %w1,%0":"=a" (value):"Nd" (port)); + __asm__ volatile ("inw %w1,%0":"=a" (value):"Nd" (port)); return value; }
static inline void outl(uint32_t value, uint16_t port) { - asm volatile ("outl %0,%w1": :"a" (value), "Nd" (port)); + __asm__ volatile ("outl %0,%w1": :"a" (value), "Nd" (port)); }
static inline uint32_t inl(uint16_t port) { uint32_t value; - asm volatile ("inl %1,%0":"=a" (value):"Nd" (port)); + __asm__ volatile ("inl %1,%0":"=a" (value):"Nd" (port)); return value; } #endif Index: flashrom-c99_clean/serprog.c =================================================================== --- flashrom-c99_clean/serprog.c (revision 1199) +++ flashrom-c99_clean/serprog.c (working copy) @@ -19,6 +19,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
+#define _XOPEN_SOURCE 500 + #include <stdio.h> #include <stdlib.h> #include <unistd.h> Index: flashrom-c99_clean/Makefile =================================================================== --- flashrom-c99_clean/Makefile (revision 1199) +++ flashrom-c99_clean/Makefile (working copy) @@ -26,7 +26,7 @@ DIFF = diff PREFIX ?= /usr/local MANDIR ?= $(PREFIX)/share/man -CFLAGS ?= -Os -Wall -Wshadow +CFLAGS ?= -Os -Wall -Wshadow -std=c99 EXPORTDIR ?= .
WARNERROR ?= yes Index: flashrom-c99_clean/dummyflasher.c =================================================================== --- flashrom-c99_clean/dummyflasher.c (revision 1199) +++ flashrom-c99_clean/dummyflasher.c (working copy) @@ -18,6 +18,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
+#define _XOPEN_SOURCE 500 + #include <string.h> #include <stdlib.h> #include <ctype.h> Index: flashrom-c99_clean/cli_classic.c =================================================================== --- flashrom-c99_clean/cli_classic.c (revision 1199) +++ flashrom-c99_clean/cli_classic.c (working copy) @@ -21,6 +21,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
+#define _XOPEN_SOURCE 500 + #include <stdio.h> #include <fcntl.h> #include <sys/stat.h> Index: flashrom-c99_clean/dmi.c =================================================================== --- flashrom-c99_clean/dmi.c (revision 1199) +++ flashrom-c99_clean/dmi.c (working copy) @@ -18,7 +18,10 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
+#define _XOPEN_SOURCE 500 + #include <string.h> +#include <strings.h> #include <stdio.h> #include <stdlib.h>
Index: flashrom-c99_clean/layout.c =================================================================== --- flashrom-c99_clean/layout.c (revision 1199) +++ flashrom-c99_clean/layout.c (working copy) @@ -18,9 +18,12 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
+#define _XOPEN_SOURCE 500 + #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <strings.h> #include <ctype.h> #include "flash.h" #include "programmer.h" Index: flashrom-c99_clean/cbtable.c =================================================================== --- flashrom-c99_clean/cbtable.c (revision 1199) +++ flashrom-c99_clean/cbtable.c (working copy) @@ -22,6 +22,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
+#define _XOPEN_SOURCE 500 + #include <unistd.h> #include <stdio.h> #include <stdlib.h> Index: flashrom-c99_clean/dediprog.c =================================================================== --- flashrom-c99_clean/dediprog.c (revision 1199) +++ flashrom-c99_clean/dediprog.c (working copy) @@ -17,6 +17,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
+#define _XOPEN_SOURCE 500 + #include <string.h> #include <usb.h> #include "flash.h" Index: flashrom-c99_clean/buspirate_spi.c =================================================================== --- flashrom-c99_clean/buspirate_spi.c (revision 1199) +++ flashrom-c99_clean/buspirate_spi.c (working copy) @@ -17,8 +17,11 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
+#define _XOPEN_SOURCE 500 + #include <stdio.h> #include <string.h> +#include <strings.h> #include <stdlib.h> #include <ctype.h> #include <unistd.h> Index: flashrom-c99_clean/serial.c =================================================================== --- flashrom-c99_clean/serial.c (revision 1199) +++ flashrom-c99_clean/serial.c (working copy) @@ -19,6 +19,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
+#define _BSD_SOURCE + #include <stdio.h> #include <stdlib.h> #include <unistd.h> Index: flashrom-c99_clean/physmap.c =================================================================== --- flashrom-c99_clean/physmap.c (revision 1199) +++ flashrom-c99_clean/physmap.c (working copy) @@ -20,6 +20,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
+#define _XOPEN_SOURCE 500 + #include <unistd.h> #include <stdio.h> #include <stdlib.h> Index: flashrom-c99_clean/spi.c =================================================================== --- flashrom-c99_clean/spi.c (revision 1199) +++ flashrom-c99_clean/spi.c (working copy) @@ -22,7 +22,7 @@ * Contains the generic SPI framework */
-#include <string.h> +#include <strings.h> #include "flash.h" #include "flashchips.h" #include "chipdrivers.h" Index: flashrom-c99_clean/ft2232_spi.c =================================================================== --- flashrom-c99_clean/ft2232_spi.c (revision 1199) +++ flashrom-c99_clean/ft2232_spi.c (working copy) @@ -20,8 +20,11 @@
#if CONFIG_FT2232_SPI == 1
+#define _XOPEN_SOURCE 500 + #include <stdio.h> #include <string.h> +#include <strings.h> #include <stdlib.h> #include <ctype.h> #include "flash.h" Index: flashrom-c99_clean/chipset_enable.c =================================================================== --- flashrom-c99_clean/chipset_enable.c (revision 1199) +++ flashrom-c99_clean/chipset_enable.c (working copy) @@ -26,6 +26,7 @@ */
#define _LARGEFILE64_SOURCE +#define _XOPEN_SOURCE 500
#include <stdlib.h> #include <string.h> Index: flashrom-c99_clean/flashrom.c =================================================================== --- flashrom-c99_clean/flashrom.c (revision 1199) +++ flashrom-c99_clean/flashrom.c (working copy) @@ -21,6 +21,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
+#define _XOPEN_SOURCE 500 + #include <stdio.h> #include <sys/types.h> #ifndef __LIBPAYLOAD__ Index: flashrom-c99_clean/udelay.c =================================================================== --- flashrom-c99_clean/udelay.c (revision 1199) +++ flashrom-c99_clean/udelay.c (working copy) @@ -21,6 +21,8 @@
#ifndef __LIBPAYLOAD__
+#define _XOPEN_SOURCE 500 + #include <unistd.h> #include <sys/time.h> #include <stdlib.h> @@ -35,7 +37,7 @@ unsigned long i; for (i = 0; i < usecs * micro; i++) { /* Make sure the compiler doesn't optimize the loop away. */ - asm volatile ("" : : "rm" (i) ); + __asm__ volatile ("" : : "rm" (i) ); } }
Index: flashrom-c99_clean/board_enable.c =================================================================== --- flashrom-c99_clean/board_enable.c (revision 1199) +++ flashrom-c99_clean/board_enable.c (working copy) @@ -24,7 +24,7 @@ * Contains the board specific flash enables. */
-#include <string.h> +#include <strings.h> #include "flash.h" #include "programmer.h"