Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
I'm going to be porting my unfinished CC22 entry to C for a "normal" release, and I'm fairly new to C. This would be my first game in C, too. Expect this as a help thread/ progress thread Razz

So... how does one do labels and gotos in C, or do you need to 'include' a C file when you want to use it as a label? (See EXAMPLE)


Code:
EXAMPLE
label.c has the contents of 'Lbl A'

//main.c
...
#include "label.c" //Goto (and theoretically Return) A
SM84CE wrote:
I'm going to be porting my unfinished CC22 entry to C for a "normal" release, and I'm fairly new to C. This would be my first game in C, too. Expect this as a help thread/ progress thread Razz

So... how does one do labels and gotos in C, or do you need to 'include' a C file when you want to use it as a label? (See EXAMPLE)


Code:
EXAMPLE
label.c has the contents of 'Lbl A'

//main.c
...
#include "label.c" //Goto (and theoretically Return) A


This page explains labels in C well. Notice that it actually warns you against using the goto statement.

If you want to return values then you could use functions.
Here's an example function. (This example has no practical use, it simply exists to show functions. If I wanted to do something similar to this I'd just use a macro or constant instead.)

Code:

int returnFive(); //Function prototype, just declaring this exists.

void main() { //This function is run when the program is run
//stuff...
printf("%d",returnFive()); //Prints the result of 'returnFive()' to console
//...more stuff
}

int returnFive() {
return 5;
}


Notice how I never said you should do any of this because everything I might do could be wrong/improper. Even when I said you could use functions I used the word could, making it your choice. Evil or Very Mad
Never use labels or goto unless you have a very very good reason to. Please look at all the useful examples that come with the toolchain download.
Yeah, C provides richer primitives than goto and labels, which are nearly always preferred - especially in a first C program Smile
What you want to do is almost certainly not even legal in C: you cannot use goto to jump into a different function. (While C technically allows splitting a function across multiple files, I've never seen that done.) There is technically a way around that restriction, but it is much more complicated to use and is only used for implementing advanced techniques like closures and coroutines. C's function and looping constructs are far easier and more pleasant to use.

More required reading for using goto.
So based off of this, I assume it's better to use different functions in different files and call them as necessary?

DrDnar wrote:

lol Smile Very Happy
Just use functions in the same file.
So I keep getting this error:

Code:

C:\Users\Sanjivan\Documents\GitHub\FusionSim\src\main.c
C:\USERS\SANJIVAN\DOCUMENTS\GITHUB\FUSIONSIM\SRC\MAIN_LOOP.C    (2,9) : ERROR (217) Cannot open include file "stdbool.h"
P1: Internal Error(0xFFC2A5)
        Please contact Technical Support
 File: C:\USERS\SANJIVAN\DOCUMENTS\GITHUB\FUSIONSIM\SRC\MAIN_LOOP.C
 Relative Line: 2
make: *** [obj/main.src] Error -1


I cloned the repo to my other laptop, in hopes of the SDK not being wacky there. No luck. People in SAX also suggested that I move the folder to a shorter path, which I did on my old laptop (to C;/SM CE C/FusionSim/), and ran `make` again. Still same error. I'm hoping someone could shed light on this, the error popped up after I declared a boolean in main_loop.c I can provide code if needed, but the "line 2" is "#includes <stdbool.h>" and the boolean in=s declared as such:

Code:
bool Reheat;
...
Reheat = false;


EDIT: SDK V8.5 and 8.3 give the same error

GitHub https://github.com/SanjivanM/FusionSim/tree/master/src
Ok, fixed those errors, it was simply me not knowing Razz

Now, any suggestions for possible upgrades? I have in mind: Increasing max flow rate and max fuel. I might reduce the initial max down from 1,000,000 mL to something else...
I'll also make a "fuel" store, where you can buy specific amounts of fuel.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement