const help
Re:const help
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
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
man, this looks like pascal to me (with a main()?!?!)...
which book you said you're learning from?
which book you said you're learning from?
Re:const help
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*
*shrugs*
Re:const help
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.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:const help
/* -------------------------------------------------------------- */
/* Report an Error */
What kind of "conversion" is this ??
C code for it is
/* Report an Error */
Code: Select all
procedure Error(s: string);
begin
WriteLn;
WriteLn(^G, 'Error: ', s, '.');
end;
C code for it is
Code: Select all
void Error(char * str) {
printf("\n\aError: %s.\",str);
}
Re:const help
Code: Select all
int bla = 0;
bla ^= 'I';
but
Code: Select all
int bla = ^I;
Re:const help
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:
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.
Code: Select all
#define FOO 1
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
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
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.
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
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
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
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