Page 1 of 2

const help

Posted: Mon Oct 14, 2002 5:35 pm
by beyondsociety
[attachment deleted by admin]

Re:const help

Posted: Mon Oct 14, 2002 5:50 pm
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

Re:const help

Posted: Mon Oct 14, 2002 6:26 pm
by dronkit
man, this looks like pascal to me (with a main()?!?!)...
which book you said you're learning from? ;)

Re:const help

Posted: Mon Oct 14, 2002 6:31 pm
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*

Re:const help

Posted: Mon Oct 14, 2002 6:34 pm
by dronkit
interesting...

Re:const help

Posted: Mon Oct 14, 2002 10:28 pm
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.

Re:const help

Posted: Tue Oct 15, 2002 3:47 am
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);
}

Re:const help

Posted: Tue Oct 15, 2002 7:52 am
by Tom
you can't use ^I like that in C! ( i think )

Re:const help

Posted: Tue Oct 15, 2002 8:38 am
by Whatever5k

Code: Select all

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

Code: Select all

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

Re:const help

Posted: Tue Oct 15, 2002 9:49 am
by grey wolf
[attachment deleted by admin]

Re:const help

Posted: Tue Oct 15, 2002 10:15 am
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.

Re:const help

Posted: Tue Oct 15, 2002 10:49 am
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.

Re:const help

Posted: Tue Oct 15, 2002 11:30 am
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.

Re:const help

Posted: Tue Oct 15, 2002 3:26 pm
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

Re:const help

Posted: Tue Oct 15, 2002 3:27 pm
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