Note that there are some explanatory texts on larger screens.

plurals
  1. POManaging without Objects in C - And, why can I declare variables anywhere in a function in C?
    primarykey
    data
    text
    <p>everyone. I actually have two questions, somewhat related.</p> <p>Question #1: Why is gcc letting me declare variables after action statements? I thought the C89 standard did not allow this. (GCC Version: 4.4.3) It even happens when I explicitly use <code>--std=c89</code> on the compile line. I know that most compilers implement things that are non-standard, i.e. C compilers allowing <code>//</code> comments, when the standard does not specify that. I'd like to learn just the standard, so that if I ever need to use <em>just</em> the standard, I don't snag on things like this.</p> <p>Question #2: How do you cope without objects in C? I program as a hobby, and I have not yet used a language that does not have Objects (a.k.a. OO concepts?) -- I already know some C++, and I'd like to learn how to use C on it's own. Supposedly, one way is to make a POD struct and make functions similar to <code>StructName_constructor()</code>, <code>StructName_doSomething()</code>, etc. and pass the struct instance to each function - is this the 'proper' way, or am I totally off?</p> <p>EDIT: Due to some minor confusion, I am defining what my second question is more clearly: I am not asking <code>How do I use Objects in C?</code> I am asking <code>How do you manage without objects in C?</code>, a.k.a. how do you accomplish things without objects, where you'd normally use objects?</p> <p>In advance, thanks a lot. I've never used a language without OOP! :) </p> <p>EDIT: As per request, here is an example of the variable declaration issue:</p> <pre><code>/* includes, or whatever */ int main(int argc, char *argv[]) { int myInt = 5; printf("myInt is %d\n", myInt); int test = 4; /* This does not result in a compile error */ printf("Test is %d\n", test); return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload