oleksandrzelentsov / levenstein_distance

Implementation of Levenstein distance in C with comparison between several languages.
2 stars 2 forks source link

Compilation doesn't work on older GCC versions #16

Closed thamerla closed 7 years ago

thamerla commented 7 years ago

As I was learning stuff related to build automation and was looking for a small project that I was able to compile fast, I tried compiling levenstein_distance on enterprise distros in the cloud (centos7/ubuntu14.04). However, I encountered the following issue:

gcc -c -Wall levenstein_distance.c -o levenstein_distance.o
levenstein_distance.c: In function 'print_distance_of_combinations':
levenstein_distance.c:62:5: error: 'for' loop initial declarations are only allowed in C99 mode
     for(int i = 0; i < length - 1; ++i)
     ^
levenstein_distance.c:62:5: note: use option -std=c99 or -std=gnu99 to compile your code
levenstein_distance.c:67:13: error: redefinition of 'i'
     for(int i = 0; i < length - 1; ++i)
             ^
levenstein_distance.c:62:13: note: previous definition of 'i' was here
     for(int i = 0; i < length - 1; ++i)
             ^
levenstein_distance.c:67:5: error: 'for' loop initial declarations are only allowed in C99 mode
     for(int i = 0; i < length - 1; ++i)
     ^
levenstein_distance.c:69:9: error: 'for' loop initial declarations are only allowed in C99 mode
         for (int j = i + 1; j < length; ++j)
         ^
levenstein_distance.c: In function 'print_distance_of_combinations_part':
levenstein_distance.c:81:5: error: 'for' loop initial declarations are only allowed in C99 mode
     for(int i = 0; i < length - 1; ++i)
     ^
levenstein_distance.c:87:13: error: redefinition of 'i'
     for(int i = 0; i < length; ++i)
             ^
levenstein_distance.c:81:13: note: previous definition of 'i' was here
     for(int i = 0; i < length - 1; ++i)
             ^
levenstein_distance.c:87:5: error: 'for' loop initial declarations are only allowed in C99 mode
     for(int i = 0; i < length; ++i)
     ^
make: *** [levenstein_distance.o] Error 1

In order to reproduce, the following shell script requiring docker may be executed:

#!/bin/sh

mkdir -p test1  &&

echo "FROM centos:7

RUN yum update -y &> /dev/null && \
  yum install -y git make gcc &> /dev/null

WORKDIR /root

RUN git clone https://github.com/oleksandrzelentsov/levenstein_distance project
RUN cd project && make" > test1/Dockerfile && docker build --force-rm -t test1 test1

rm -rf test1

It seems that while the newest GCC enables C99 by default, those older versions do not. I think you can either enforce C99 (seems to be the easiest solution, as it's an old standard supported anyway) or make the code ANSI C compatible. I can provide a quick fix enforcing C99, but first let me know what do you think about this.

oleksandrzelentsov commented 7 years ago

Please, try to use make instead.

thamerla commented 7 years ago

I use make (as specified in the reproduce part) and this is the result.

oleksandrzelentsov commented 7 years ago

Code is meant to be compiled with C11

oleksandrzelentsov commented 7 years ago

Also, try the dev branch

oleksandrzelentsov commented 7 years ago

There it is written explicitly

oleksandrzelentsov commented 7 years ago

Just gotta finish the work and merge it into master

oleksandrzelentsov commented 7 years ago

Fixed by #17, try now

oleksandrzelentsov commented 7 years ago

@nonyy Also, if you consider creating Docker image, I will be grateful if you'll provide it there #18. Also, try to resolve it if you are interested.

thamerla commented 7 years ago

@oleksandrzelentsov Works now.