question about parentheses and square brackets

For developers writing C++, Fortran, Java, code who have questions or comments to make.

Moderators: silvia, selimgunay, Moderators

Post Reply
buddhasarah
Posts: 93
Joined: Thu Feb 12, 2009 8:31 pm
Location: The University of Tokyo

question about parentheses and square brackets

Post by buddhasarah » Tue May 22, 2012 10:38 pm

I have a question about the usage of parentheses and square brackets in OpenSees's code. The following code is a small section from the OpenSees source code, I guess the both "connectedExternalNodes(0)" and "theNodes[0]" means the first cell of "connectedExternalNodes" and "theNodes" array respectively. But why the former uses parentheses while the latter uses square brackets? The lower code is another similar example with the same question. Thank you very much in advance!
#####################################
// Set connected external node IDs
connectedExternalNodes(0) = nd1;
connectedExternalNodes(1) = nd2;

theNodes[0] = 0;
theNodes[1] = 0;
#####################################
q(0) += q0[0];
q(1) += q0[1];
q(2) += q0[2];
#######################################

leon1977
Posts: 2
Joined: Fri May 25, 2012 4:49 pm
Contact:

Re: question about parentheses and square brackets

Post by leon1977 » Fri May 25, 2012 4:59 pm

Thankyou so much, it really helped alot!!

fmk
Site Admin
Posts: 5883
Joined: Fri Jun 11, 2004 2:33 pm
Location: UC Berkeley
Contact:

Re: question about parentheses and square brackets

Post by fmk » Fri Jun 01, 2012 3:53 pm

theNodes, q0 are array's and the [] are used in c or c++ to reference a member of the array.

q, connectedNodes are of type vector and id, these are c++ classes i have defined which have overloaded operators (). these () operators also access the components, but check the range of the indices is valid.

billjhonson
Posts: 1
Joined: Tue Sep 11, 2012 2:26 am
Location: USA
Contact:

Re: question about parentheses and square brackets

Post by billjhonson » Tue Sep 11, 2012 2:39 am

Thanks for the greatest news about parentheses and square brackets. It's really help to everyone.............

linguan118
Posts: 140
Joined: Sun Oct 03, 2010 11:36 pm
Location: Hong Kong

Re: question about parentheses and square brackets

Post by linguan118 » Fri Oct 12, 2012 7:33 pm

Yes, very helpful!
Matrix belongs to arrays, right?
Research Assistant Professor, The Hong Kong Polytechnic University
guanlin@polyu.edu.hk

Post Reply