Re: XForms: Segmentation Faults with C++

Alberto BARSELLA (ishark@lsh01.univ-lille1.fr)
Thu, 25 Feb 1999 16:58:04 +0000 (/etc/localtime)

# To subscribers of the xforms list from Alberto BARSELLA <ishark@lsh01.univ-lille1.fr> :

Hi,

> Do you know what's wrong with the following code ?

Yes, you've been using fortran too much :)

> FL_OBJECT *Fieldbuttons[12][12];

A 12x12 matrix. Fine.

> for (counter1=1;counter1<=12;counter1++)
> {
> for (counter2=1;counter2<=12;counter2++)
> {
> Fieldbuttons[counter1][counter2] = ....

Boom! Contrary to several other languages, C (and C++) arrays/matrices are
0-based, which means that in your code you must use counters from 0 to 11
and not from 1 to 12.
Of course C/C++ provide no range checking, as it would slow down the app :)

Since you're going to C++ I suggest that you look at the standard library,
which includes some classes (templates, actually) for less explosive
containers (they tend to throw exceptions instead of exploding with a
segmentation fault...).

Bye,
Alberto

PS: C/C++-oriented questions are more suited for a C/C++ discussion
forum.

--
Alberto BARSELLA
PGP fingerprint = 13 3F 22 D2 0B 0A D3 25  F1 89 FE B5 82 AD 75 2A
** Beliefs are dangerous. Beliefs allow the mind to stop functioning.
A non-functioning mind is clinically dead.  Believe in nothing... **

_________________________________________________ To unsubscribe, send the message "unsubscribe" to xforms-request@bob.usuhs.mil or see http://bob.usuhs.mil/mailserv/xforms.html XForms Home Page: http://bragg.phys.uwm.edu/xforms List Archive: http://bob.usuhs.mil/mailserv/list-archives/