const help

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
beyondsociety

const help

Post by beyondsociety »

[attachment deleted by admin]
gtsphere

Re:const help

Post by gtsphere »

you need to define a return type, in example: int char float double

so what you need to do is:

const int TAB = ^I;

so you can change it to whatever tha ttype of variable is. Now if you're trying to make TAB equal that you could use a #define.

#define TAB ^I

and that will allow you to use TAB and it will always be equal to ^I

i hope this helps out
-GTsphere
dronkit

Re:const help

Post by dronkit »

man, this looks like pascal to me (with a main()?!?!)...
which book you said you're learning from? ;)
gtsphere

Re:const help

Post by gtsphere »

thats what i thought. that code looked vagely familiar to a site i saw about compiler deisgn, cept all the code was in pascal

*shrugs*
dronkit

Re:const help

Post by dronkit »

interesting...
beyondsociety

Re:const help

Post by beyondsociety »

Yes, its based on the compiler design thats in pascal. I am trying to convert it to c code. I have not been having any luck with it.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:const help

Post by Pype.Clicker »

/* -------------------------------------------------------------- */
/* Report an Error */

Code: Select all

procedure Error(s: string);
begin
   WriteLn;
   WriteLn(^G, 'Error: ', s, '.');
end;
What kind of "conversion" is this ??

C code for it is

Code: Select all

void Error(char * str) {
   printf("\n\aError: %s.\",str);
}
Tom

Re:const help

Post by Tom »

you can't use ^I like that in C! ( i think )
Whatever5k

Re:const help

Post by Whatever5k »

Code: Select all

int bla = 0;
bla ^= 'I';
works...
but

Code: Select all

int bla = ^I;
will never work...
grey wolf

Re:const help

Post by grey wolf »

[attachment deleted by admin]
Schol-R-LEA

Re:const help

Post by Schol-R-LEA »

While 'const' is a keyword in C, it doesn't actually do anything, IIRC; the variable so declared is treated as a normal variable. It was added because it was used in C++ and many C/C++ compilers (e.g., gcc) were accepting it in both. The traditional way to declare a constant in C is to use a macro define, like so:

Code: Select all

#define FOO 1 
You can use const in the normal way, if you way, but don't rely on it to catch any mistakes.

As for the other big puzzle, well, I guess most of you never took Pascal or Modula-2 in the old days, or else have forgotten it. In the expression

foo := ^bar;

'^bar' is a pointer dereference, not an exclusive-or (unlike C, or Wirth's later languages like Oberon, Pascal has no built-in bitwise operators - though the set type could be used to more or less the same effect, being usually implemented as a bitfield). The equivalent in C is

foo = *bar;

HTH.
Tim

Re:const help

Post by Tim »

The OP's use of the ^ character in the original source (e.g. ^G) is the Pascal way of specifying control characters (read ^G as Ctrl+G). ^A is ASCII 1, ^B = 2, ^C = 3, etc. Hence ^I becomes Tab, which is '\t' in C.
beyondsociety

Re:const help

Post by beyondsociety »

Sorry about the mix up. I was trying to convert the code from pascal to c. I only converted a few lines and the rest was in pascal. I have fixed most of it. I am having a few errors though.

Is there somewhere I can find a list of errors for the C language?. If possible, also solutions to the errors. This would help me out greatly.
gtsphere

Re:const help

Post by gtsphere »

http://www.comsc.ucok.edu/~pcarter/faq/ ... rrors.html

that link has some common errors, but depending on what you get (error wise) it could be compiler specific, IE: Using inline ASM, etc
Tom

Re:const help

Post by Tom »

beyondsociety, I use TC once in a while, if you need to ask about a error message, just reply the messages you get, and i'll tell you what they mean
Post Reply