Sponsored Content
Top Forums Programming -Warray-bounds option to GCC compiler Post 303013096 by bakunin on Wednesday 14th of February 2018 10:57:00 PM
Old 02-14-2018
Quote:
Originally Posted by milhan
If I assign 10000 to index, program give segmentation fault, but still compiles with no warnings. -Warray-bounds switch is on.
OK, now i understand better what your question is about. For reference i modified your program this way:

Code:
#include <iostream>
using namespace std;

int main()
{
        const int index=1000;
        int numbers[8] = {1,2,3,4,5,6,7,8};

        numbers[index] = 999;
        cout << numbers[index] << endl;

        return 0;
}

and used this compiler version:

Code:
# g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.6) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.

with the same results.

The problem IMHO is a misunderstanding of runtime-bounds-checking and compile-time bounds-checking. Runtime bounds-checking is included in the frontend (if at all) and this is only done for C but not for C++ according to this source. The link also mentions other options (mudflap, MIRO, valgrind, ...), which i haven't tested at all (i haven't programmed anything worthwhile in a HLL for a long time).

As far as i have understood the GNU compiler suite allows for switching on runtime bounds-checking, which the C-frontend does provide but the g++-frontend does not.

None of the frontends do compile-time bounds-checking (which you seem to be after) and, frankly, i doubt this is possible to do in a general way. The compiler would have to guess at compile-time which values any expression could evaluate to, which not only would need arbitrary computing time but also would need to decide the "Entscheidungsproblem - Wikipedia", which is proven to be undecidable (see also "halting problem in Turing-machines").

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

cc compiler / gcc

:confused: I have a question concerning gcc. IŽd like to install the gcc on my Mac OS X, but when I try to run the configure command I get the following message: floriant% ./configure ./configure: read-only variable: PWD Configuring for a powerpc-apple-darwin5.4 host. *** This configuration... (2 Replies)
Discussion started by: florian.turck
2 Replies

2. Programming

gcc compiler

i write c++ code it run perfectely with g++ compiler but same code when i compile with GCC compiler it gives linker error , followed these linker error /tmp/ccfZtXOQ.o(.text+0x22): In function `main': conf_system.cpp: undefined reference to `operator new(unsigned int)'... (5 Replies)
Discussion started by: munnu
5 Replies

3. UNIX for Dummies Questions & Answers

xl C/C++ compiler to GCC compiler

Hi, we are converting from IBM-AIX(xl c/c++ compiler) to Linux(GCC complier). As a part of this i need to change the CFLAGS. The xl c/c++ complier CFLAGS is CFLAGS := $(CDEBUG) $(PROJECT_INCLUDE_DIRS) $(COBJECT_MODE) -qcpluscmt -qmakedep -qcheck=all \ -qalign=bit_packed $(LINT_FLAGS)... (0 Replies)
Discussion started by: pbattu1
0 Replies

4. AIX

AIX 5.3 gcc compiler

Hi there I've got a problem getting my mysql libraries to work. every time I compile my source code it gives my a compiler error. Cannot find a rule to create target /usr/include/mysql/mysql.h AND /usr/include/mysql/mysql.h: Permission denied Is anyone fimiliar with this error, and can... (1 Reply)
Discussion started by: cipher#1
1 Replies

5. Ubuntu

gcc compiler

where to download gcc compiler for ubuntu? how to install? how to build and run "c programs"? screen shots if possible.....:b::D tutorials too:cool: (5 Replies)
Discussion started by: villanarun
5 Replies

6. Shell Programming and Scripting

gcc compiler

I am using open suse linux. I want to install gcc compiler in my machine. I ahve checked man gcc and man cc. But it's not there. Can someone help me (4 Replies)
Discussion started by: pritish.sas
4 Replies

7. Programming

gcc compiler

Which gcc compiler release had the Arm 9 multicore support?Whether the compiler that used for the single Arm 9 core can be used for its multicore systems ? If gcc not support,please tell me which are the compilers that are available for Arm 9 multicore systems (including commerical).Whether... (0 Replies)
Discussion started by: sujith4u87
0 Replies

8. UNIX for Dummies Questions & Answers

cc compiler and gcc compiler

hi, can we install gcc compiler in unix based OS(sun solar,IBM AIX,HP,etc) and also can we install sun cc compiler in AIX environment and vice versa. and more ..is linux support cc compiler regards Ajay (3 Replies)
Discussion started by: ajaysahoo
3 Replies

9. Programming

A question regarding the gcc compiler ...

It might be a simple one but I have this question bothering me for sometime. When we do a symbol search inside the library directory (i.e. /usr/lib/*) via tools like nm; it takes a while to give us the results. However, its very quick when gcc is invoked to compile a program with the very same... (11 Replies)
Discussion started by: Praveen_218
11 Replies
ZIP_GET_NAME(3) 					     Library Functions Manual						   ZIP_GET_NAME(3)

NAME
zip_get_name - get name of file by index LIBRARY
libzip (-lzip) SYNOPSIS
#include <zip.h> const char * zip_get_name(struct zip *archive, int index, int flags); DESCRIPTION
The zip_get_name function returns the name of the file at position index in archive. If flags is set to ZIP_FL_UNCHANGED, the original unchanged filename is returned. The returned string must not be modified or freed, and becomes invalid when archive is closed. RETURN VALUES
Upon successful completion, a pointer to the name is returned. Otherwise, NULL and the error code in archive is set to indicate the error. ERRORS
zip_get_name fails if: [ZIP_ER_DELETED] index refers to a file that has been deleted (see zip_delete(3) ). [ZIP_ER_INVAL] index is not a valid file index in archive, or index points to an added file and ZIP_FL_UNCHANGED is set. SEE ALSO
libzip(3), zip_name_locate(3) AUTHORS
Dieter Baron <dillo@giga.or.at> and Thomas Klausner <tk@giga.or.at> NiH January 20, 2005 ZIP_GET_NAME(3)
All times are GMT -4. The time now is 11:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy