1

I'm trying out OpenCobol with a simple Hello World example.

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.
PROCEDURE DIVISION.
    DISPLAY "Hello World".
    STOP RUN.

I compile with

cobc -x -free -o hello hello.cbl

And get a workable executable, but also a lot of these warnings from gcc

warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

From a Google search all I can find is that I can apparently just ignore these without ill effect. But for various reasons I'd like to actually get rid of them, if nothing else then at least suppressing them somehow. How can I do this?

4 Answers4

3

Use -O to tone down optimisation.

I would have expected this was being applied to the C Code generation, and not passed through to gcc.

If you prefer absolute control over gcc,

Write a script to wrap your build. (pass 1) To produce translated C code from cobc. (pass 2) To compile (with lesser Optimisation) using gcc. On a large project you can nest scripts for a full build ala make.

mckenzm
  • 1,545
  • 1
  • 12
  • 19
  • Before you downvote this, it was written some time ago, the current build behaviour 12/2014 is not the same. In any case if you are debugging the script approach may still be pertinent. Since you will be debugging with C source in any case. – mckenzm Dec 12 '14 at 02:53
1

Excuse the late note;

For control over the C compiling phase, OpenCOBOL respects a few environment variables during the build chain.

See http://opencobol.add1tocobol.com/#does-opencobol-work-with-llvm for a list, including COB_CFLAGS and COB_LDFLAGS

Brian Tiffin
  • 3,978
  • 1
  • 24
  • 34
0

From this OpenCobol forum thread it looks like you need to use the -fno-strict-aliasing option. Can't try it here because we don't use OpenCobol.

DuncanKinnear
  • 4,563
  • 2
  • 34
  • 65
  • Mmmmm. Just downloaded version 1.1 of OpenCobol onto my Fedora 14 machine, created your sample program and compiled. I don't get any messages and it compiles and executes fine. What version are you using? – DuncanKinnear Mar 26 '12 at 03:49
  • 1
    It doesn't seem to work. These are all options that apply to GCC, but OpenCobol doesn't understand them or pass them on. I just get an "unrecognized option" warning. Right now I'm using `>/dev/null 2>&1` to get rid of all the output, but it'd be nice to not throw away everything including any potential real errors. I use OpenCobol 1.0.0 and GCC 4.6.1, the errors come from GCC but I can't pass options to GCC because it's called through OpenCobol –  Mar 26 '12 at 11:52
  • When you do a `cob-config --cflags` what do you get? I get: `-I/usr/include -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i686 -mtune=atom -fasynchronous-unwind-tables -fPIC`. Can you upgrade to version 1.1 to see if it makes a difference? – DuncanKinnear Mar 26 '12 at 19:34
  • `command not found` - And I'd prefer not to get into upgrading. –  Mar 28 '12 at 09:40
-1

Somewhere under the covers you are invoking the gcc compiler. Try setting compiler options to turn the warning off as described here

The option should look something like: -Wno-strict

NealB
  • 16,670
  • 2
  • 39
  • 60
  • Doesn't appear to work. I tried `-Wno-strict` and `Wno-strict-aliasing`, but I don't think OpenCobol passes it on to gcc –  Mar 16 '12 at 14:40