c++ define variable inside if block for function scope -
Background: I am working on the development of a number of different controllers (10 or more) for a hardware that needs to run code in code. Under RTAI Linux, I implemented a class as a separate member function of the class with each controller. I am looking to pass the desired route for each of these control functions for the respective control variables on which the controller has been selected. Additionally, because there are many criteria for each controller and I'm looking to completely switch the whole code and controllers that navigate without navigating parameters, I define all the control variables in one place and I'm trying to define on the basis of controllers. I choose to run here. Here's a minimal work example of what I'm looking for.
I am looking to define the variable based on a condition that is correct or not:
int foo () {Int i = 0; If (i == 0) {int a = 0; Float b = 1; Double c = 10; } Elseif (i == 1) {int e = 0; Float F = 1; Double g = 10; } // Lock / Memory // for hard real-time execution while working hard in real time (some conditions) {// 100 lines code if (i == 0) {a = a + 1; B = b * 2; C = c * 4; // 100 lines of code} elseif (i == 1) {e = e * e * e; F = f * 3; G = G * 10; // 100 lines code} // lines of code 100}} in real-time strict execution} The above code executes the error as the radius of the variable if the block block Relating to related is limited in defined in. Can anyone recommend a better way of handling this issue? What is the best practice in this context in C ++?
In your case, you can just use:
Int foo () {int i = 0; If (i == 0) {int a = 0; Float b = 1; Double c = 10; For (int j = 1; j and lt; 10; j ++) {a = a + 1; B = B * 2; C = C * 4; }} And if (i == 1) {int e = 0; Float F = 1; Double g = 10; For (int j = 1; j and lt; 10; j ++) {e = e * e * e; F = f * 3; G = G * 10; }}} or better, create sub-functions
zero foo0 () {int a = 0; Float b = 1; Double c = 10; For (int j = 1; j and lt; 10; j ++) {a = a + 1; B = B * 2; C = C * 4; }} Void foo1 () {// .. E, F, G} with int () stuff {int i = 0; If (i == 0) {foo0 (); } And if (i == 1) {foo1 (); }}
Comments
Post a Comment