Discussion:
hypenator.cc errors
Chris Sorenson
2013-09-02 09:25:39 UTC
Permalink
Greets all,

Another sequence of bads that cropped up using the Silicon
Graphics MIPSpro compiler, any thoughts? To wit:

cc-1028 CC: ERROR File = hyphenator.cc, Line = 147
The expression used must have a constant value.

char chars [l + 1];
^

cc-1028 CC: ERROR File = hyphenator.cc, Line = 185
The expression used must have a constant value.

char noHyphens[len - 2 * breaks->size() + 1];
^

cc-1028 CC: ERROR File = hyphenator.cc, Line = 185
The expression used must have a constant value.

char noHyphens[len - 2 * breaks->size() + 1];
^

cc-1060 CC: ERROR File = hyphenator.cc, Line = 185
The indicated operator is not allowed in an integral
constant expression.

char noHyphens[len - 2 * breaks->size() + 1];
^

cc-1059 CC: ERROR File = hyphenator.cc, Line = 185
A function call is not allowed in a constant expression.

char noHyphens[len - 2 * breaks->size() + 1];
^

cc-1028 CC: ERROR File = hyphenator.cc, Line = 316
The expression used must have a constant value.

char work[strlen (wordLc) + 3];
^

cc-1059 CC: ERROR File = hyphenator.cc, Line = 316
A function call is not allowed in a constant expression.

char work[strlen (wordLc) + 3];
^

cc-1028 CC: ERROR File = hyphenator.cc, Line = 316
The expression used must have a constant value.

char work[strlen (wordLc) + 3];
^

8 errors detected in the compilation of "hyphenator.cc".
make: *** [hyphenator.o] Error 2
Sebastian Geerken
2013-09-02 10:34:41 UTC
Permalink
Post by Chris Sorenson
Greets all,
Another sequence of bads that cropped up using the Silicon
cc-1028 CC: ERROR File = hyphenator.cc, Line = 147
The expression used must have a constant value.
char chars [l + 1];
^
[more similar cases]
It seems that your compiler does not support arrays with variable
length, which are standard since C99, as far as I see. It could be
fixed by replacing this line (as an example) by:

char *chars = new char [l + 1];

and later

delete[] chars;

However, I'd like to check other possibilities. A short search lead me
to <http://www.sgi.com/products/software/irix/tools/c.html>, according
to which newer versions support C99. Which version do you use?

Sebastian
Chris Sorenson
2013-09-02 17:51:27 UTC
Permalink
Post by Sebastian Geerken
Post by Chris Sorenson
Greets all,
Another sequence of bads that cropped up using the
cc-1028 CC: ERROR File = hyphenator.cc, Line = 147
The expression used must have a constant value.
char chars [l + 1];
^
[more similar cases]
It seems that your compiler does not support arrays with
variable length, which are standard since C99, as far as I
see. It could be fixed by replacing this line (as an
char *chars = new char [l + 1];
and later
delete[] chars;
However, I'd like to check other possibilities. A short
search lead me to
<http://www.sgi.com/products/software/irix/tools/c.html>,
according to which newer versions support C99. Which
version do you use?
I'm using MIPSpro 7.4.3 (the most current version is 7.4.4)
but in C99 mode it can't compile C++ code. Not to worry I'll
#ifdef my way around the variable length arrays, I guess I
didn't look closely enough to realize that was what those
were, thanks!
Sebastian Geerken
2013-09-04 09:22:25 UTC
Permalink
Post by Chris Sorenson
Post by Sebastian Geerken
Post by Chris Sorenson
Greets all,
Another sequence of bads that cropped up using the
cc-1028 CC: ERROR File = hyphenator.cc, Line = 147
The expression used must have a constant value.
char chars [l + 1];
^
[more similar cases]
It seems that your compiler does not support arrays with
variable length, which are standard since C99, as far as I
see. It could be fixed by replacing this line (as an
char *chars = new char [l + 1];
and later
delete[] chars;
However, I'd like to check other possibilities. A short
search lead me to
<http://www.sgi.com/products/software/irix/tools/c.html>,
according to which newer versions support C99. Which
version do you use?
I'm using MIPSpro 7.4.3 (the most current version is 7.4.4)
but in C99 mode it can't compile C++ code. Not to worry I'll
#ifdef my way around the variable length arrays, I guess I
didn't look closely enough to realize that was what those
were, thanks!
Thinking about it again, variable length arrays are a feature of C,
but not of C++, although it seems that most C++ compilers support it.
Since this is a nice feature, but standard C++ should be supported,
I've thought of testing it by the configure script, and then hide two
different implementations behind a macro. See attached patch, which
should be applied to the current hg repository.

What do you think?

Cris: If you run ./autogen.sh && ./configure, you should see a line:

checking for support of variable length arrays in C++... no

Is this correct?

Sebastian
Sebastian Geerken
2013-09-06 09:46:10 UTC
Permalink
Post by Sebastian Geerken
[...]
Thinking about it again, variable length arrays are a feature of C,
but not of C++, although it seems that most C++ compilers support it.
Since this is a nice feature, but standard C++ should be supported,
I've thought of testing it by the configure script, and then hide two
different implementations behind a macro. See attached patch, which
should be applied to the current hg repository.
What do you think? [...]
Third round: I agree with Jorge that this is quite too complex; and
profiling shows no performance gain of using the heap over using the
stack, so I've replaced it by new and delete. Cris: please test the
latest version from hg, it should compile now.

I've tried to force g++ to raise an error in this case, by using this
example:

---
#include <stdlib.h>

int main()
{
int n = rand() % 10 + 1;
char c[n];
}
---

but both "g++ -std=c++98 test.cc" and "g++ -std=c++11 test.cc" do not
complain. Does someone have an idea? ("g++ --version" => "g++ (Debian
4.7.2-5) 4.7.2")

Sebastian
Jorge Arellano Cid
2013-09-06 15:08:57 UTC
Permalink
Post by Sebastian Geerken
Post by Sebastian Geerken
[...]
Thinking about it again, variable length arrays are a feature of C,
but not of C++, although it seems that most C++ compilers support it.
Since this is a nice feature, but standard C++ should be supported,
I've thought of testing it by the configure script, and then hide two
different implementations behind a macro. See attached patch, which
should be applied to the current hg repository.
What do you think? [...]
Third round: I agree with Jorge that this is quite too complex; and
profiling shows no performance gain of using the heap over using the
stack, so I've replaced it by new and delete. Cris: please test the
latest version from hg, it should compile now.
There's a memory problem with the sizeof(buf) because it returns
the pointer size, not the array length!

Please see the attached test case for details.

(Compile with: g++ -W -Wall size3.cc -o size3)
--
Cheers
Jorge.-
Sebastian Geerken
2013-09-06 15:35:35 UTC
Permalink
Post by Jorge Arellano Cid
Post by Sebastian Geerken
Post by Sebastian Geerken
[...]
Thinking about it again, variable length arrays are a feature of C,
but not of C++, although it seems that most C++ compilers support it.
Since this is a nice feature, but standard C++ should be supported,
I've thought of testing it by the configure script, and then hide two
different implementations behind a macro. See attached patch, which
should be applied to the current hg repository.
What do you think? [...]
Third round: I agree with Jorge that this is quite too complex; and
profiling shows no performance gain of using the heap over using the
stack, so I've replaced it by new and delete. Cris: please test the
latest version from hg, it should compile now.
There's a memory problem with the sizeof(buf) because it returns
the pointer size, not the array length!
Please see the attached test case for details.
(Compile with: g++ -W -Wall size3.cc -o size3)
That's why paths are limited to 7 characters. :-)

Loading hyphenation patterns for language 'de' from '/usr/lo' and exceptions from '/usr/lo' ...

Anyway, fixed now.

Sebastian

Chris Sorenson
2013-09-05 02:45:54 UTC
Permalink
Post by Sebastian Geerken
Cris: If you run ./autogen.sh && ./configure, you should
Can't seem to apply the patch:

***@starhunter:~/src/dls/dillo-3.0.3$ patch <
var_len_arr_cxx.diff
(Stripping trailing CRs from patch.)
patching file configure.ac
Hunk #1 succeeded at 105 with fuzz 2.
Hunk #2 succeeded at 406 (offset -26 lines).
(Stripping trailing CRs from patch.)
can't find file to patch at input line 38
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|diff -r 808c0a0fc122 dw/hyphenator.cc
|--- a/dw/hyphenator.cc Mon Sep 02 11:31:37 2013 -0400
|+++ b/dw/hyphenator.cc Wed Sep 04 11:15:02 2013 +0200
--------------------------

Do I need to have a mercurial checked out version to use
this patch?
Sebastian Geerken
2013-09-06 09:48:20 UTC
Permalink
Post by Chris Sorenson
Post by Sebastian Geerken
Cris: If you run ./autogen.sh && ./configure, you should
var_len_arr_cxx.diff
(Stripping trailing CRs from patch.)
patching file configure.ac
Hunk #1 succeeded at 105 with fuzz 2.
Hunk #2 succeeded at 406 (offset -26 lines).
(Stripping trailing CRs from patch.)
can't find file to patch at input line 38
Perhaps you should have used the -p or --strip option?
--------------------------
|diff -r 808c0a0fc122 dw/hyphenator.cc
|--- a/dw/hyphenator.cc Mon Sep 02 11:31:37 2013 -0400
|+++ b/dw/hyphenator.cc Wed Sep 04 11:15:02 2013 +0200
--------------------------
Do I need to have a mercurial checked out version to use
this patch?
Yes, this patch is against the latest hg version; things may have
changed there.

Sebastian
Chris Sorenson
2013-09-05 02:51:48 UTC
Permalink
Trying it again with `patch -p1` I get:

(Stripping trailing CRs from patch.)
patching file configure.ac
Hunk #1 succeeded at 105 with fuzz 2.
Hunk #2 succeeded at 406 (offset -26 lines).
(Stripping trailing CRs from patch.)
patching file dw/hyphenator.cc
Hunk #1 FAILED at 49.
Hunk #2 FAILED at 118.
2 out of 5 hunks FAILED -- saving rejects to file
dw/hyphenator.cc.rej
(Stripping trailing CRs from patch.)
patching file lout/misc.hh
Loading...