Go Down

Topic: Not TRYING to start a flame war honest. (Read 5995 times) previous topic - next topic

cjdelphi

But... has C or C++ got PASCAL calling conventions?... if so is and/or/xor and not 4 part of them?..

eg...

Code: [Select]

int b;

void setup()
{
  b=10;
  //c code
  b = b ^ b;
  //C Form
  b = (b xor b);
  // xor (used in pascal);
 
  b = !b;
  //pascal
  b = not b;
 
  b = b | b;
  //pascal
  b = b or b;
 
 
  b = b & b;
  //pascal
  b = b and b;
}


void loop()
{
 
 
}


i don't have a vanilla c compiler to test this, but i find it odd, this compiles perfectly.

helps HEAPS to remember what's what for me now, and what to use. not trying to start a way, but are these operators intended? some kind of pascal/fortran influence going on there?

PaulS

Quote
But... has C or C++ got PASCAL calling conventions?... if so is and/or/xor and not 4 part of them?

No, but there are often additions to the basic C/C++ compiler to enable that sort of stuff (for the weak minded that can't remember the simple C way...)

wanderson


Quote
But... has C or C++ got PASCAL calling conventions?... if so is and/or/xor and not 4 part of them?

No, but there are often additions to the basic C/C++ compiler to enable that sort of stuff (for the weak minded that can't remember the simple C way...)


Using the C/C++ preprocessor you can accomplish a great deal in the way of making C/C++ look like another language; however this is ALWAYS a bad idea.  The resulting code is hard to manage.  No other programmers will have a simple time working on it.  And many other well documented issues.  Ultimately if you want to use PASCAL, then use pascal.  You could use the GNU Pascal to C compiler chain, in conjunction with the standard AVR C/C++ chain.  You might need to modify/create the nescessary support libraries.  There are also commercial PASCAL compilers for the AVR.

In short use the correct tool for the task, don't try to use a hammer as a wrench...
New true random number library available at: http://code.google.com/p/avr-hardware-random-number-generation/

Current version 1.0.1

AWOL

Look for a file called iso646.h.

It is hard to use a hammer as a wrench, but quite good fun to use a wrench as a hammer.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

cjdelphi

Code: [Select]

boolean you = false;
  you = not you;
  if (you == true)
    return;



scary :D

Tom Carpenter

#5
Aug 15, 2012, 04:44 pm Last Edit: Aug 15, 2012, 04:46 pm by Tom Carpenter Reason: 1
I have used this before:

Code: [Select]
#define OR ||
#define AND &&
#define XOR !=
#define NOT !

boolean a,b,c;

void setup(){
//Just demonstrations, I doubt this does anythign useful.
 a = (b XOR c);
 b = NOT b;
 c = (b AND a);
 b = (a OR b);
}


Edit:
or you can do this one for bitwise operators:
Code: [Select]
#define or |
#define and &
#define xor ^
#define not ~

byte a,b,c;

void setup(){
//Just demonstrations, I doubt this does anythign useful.
 a = 10;
 b = 103;
 c = 78
 a = (b xor c);
 b = not b;
 c = (b and a);
 b = (a or b);
}


~Tom~

MichaelMeissner


Edit:
or you can do this one for bitwise operators:
Code: [Select]
#define or |
#define and &
#define xor ^
#define not ~

byte a,b,c;

void setup(){
//Just demonstrations, I doubt this does anythign useful.
 a = 10;
 b = 103;
 c = 78
 a = (b xor c);
 b = not b;
 c = (b and a);
 b = (a or b);
}



Given the Arduino uses C++ instead of just C, you don't need the defines, since and/and_eq/or/or_eq/not/not_eq are C++ keywords that map into the C counterparts.

oric_dan

Code: [Select]

#define OR ||
#define AND &&
#define XOR !=
#define NOT !


I once knew another Pascal programmer who started writing code in C. He didn't stop as
above, but #defined every lit bit of C that he could into Pascal syntax. begin to {, end to },
= to :=, on and on to the end of time and sanity. I think for good measure, he also tossed
in a little retranslated Basic syntax.

MichaelMeissner


I once knew another Pascal programmer who started writing code in C. He didn't stop as
above, but #defined every lit bit of C that he could into Pascal syntax. begin to {, end to },
= to :=, on and on to the end of time and sanity. I think for good measure, he also tossed
in a little retranslated Basic syntax.


And this is one of the reasons I implemented the -save-temps (and more recently -save-temps=obj) option in GCC many, many years ago, so that I could see what was really being fed to the compiler when bug reports came up.  The -save-temps option leaves a copy of the output after preprocessing and the assembler input file around.

GoForSmoke


Code: [Select]

int b;

void setup()
{
  b=10;
  //c code
  b = b ^ b;
  //C Form
  b = (b xor b);
  // xor (used in pascal);
 
  b = !b;
  //pascal
  b = not b;
 
  b = b | b;
  //pascal
  b = b or b;
 
 
  b = b & b;
  //pascal
  b = b and b;
}


void loop()
{
 
 
}


Just because it compiles doesn't always mean it's going to do what you think.
Try throwing a few print statements in there, maybe we can fun over the results.
Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

PeterH


I once knew another Pascal programmer who started writing code in C. He didn't stop as
above, but #defined every lit bit of C that he could into Pascal syntax. begin to {, end to },
= to :=, on and on to the end of time and sanity. I think for good measure, he also tossed
in a little retranslated Basic syntax.


I seem to remember seeing a Jive macro set years ago that converted contemporary American slang into valid 'C'. :)
I only provide help via the forum - please do not contact me for private consultancy.

pYro_65

Quote
I seem to remember seeing a Jive macro set years ago that converted contemporary American slang into valid 'C'.


Haha, like the Simpsons example.

Quote
A whole nother = allocate some memory.

Quote
Come 'ere a minute = read value after short delay.

cjdelphi



Code: [Select]

int b;

void setup()
{
  b=10;
  //c code
  b = b ^ b;
  //C Form
  b = (b xor b);
  // xor (used in pascal);
 
  b = !b;
  //pascal
  b = not b;
 
  b = b | b;
  //pascal
  b = b or b;
 
 
  b = b & b;
  //pascal
  b = b and b;
}


void loop()
{
 
 
}


Just because it compiles doesn't always mean it's going to do what you think.
Try throwing a few print statements in there, maybe we can fun over the results.




Code: [Select]

int b;



void setup()
{
  Serial.begin(9600);
  b=1;
  //c code
  b = b ^ b;
  Serial.print("C Version: ");
  Serial.println(b);
  Serial.println();
  //C Form (interesting, does ^ not mean XOR? these conflict, the
  //rest (below match)
  b = (b xor b);
  Serial.print("Pascal Style Version: ");
  Serial.println(b);
  Serial.println();

  // xor (used in pascal);
 
  b = !b;
  Serial.print("C Version: ");
  Serial.println(b);
  Serial.println();

  //pascal
  b = not b;
  Serial.print("Pascal Style Version: ");
  Serial.println(b);
  Serial.println();

  b = b | b;
  Serial.print("C Version: ");
  Serial.println(b);
  Serial.println();

  //pascal
  b = b or b;
  Serial.print("Pascal Style Version: ");
  Serial.println(b);
  Serial.println();
 
 
  b = b & b;
  Serial.print("C Version: ");
  Serial.println(b);
  Serial.println();

  //pascal
  b = b and b;
  Serial.print("Pascal Style Version: ");
  Serial.println(b);
  Serial.println();
}


void loop()
{
 
 
}




I Think ^ is not the same as XOR but the rest seems to yeild identical values, but then my maths sucks badly, i use my fingers to count on still lol...

anyway, could someone throw it some real values to check to see what the differences actually are?

lloyddean

#13
Aug 16, 2012, 07:13 am Last Edit: Aug 16, 2012, 07:15 am by lloyddean Reason: 1
I may've missed it but nobody seems to have mentioned that the following keywords are simply part of the C++ standard.

    and
    and_eq
   bitand
   bitor
   compl
   not
   not_eq
   or
   or_eq
   xor
   xor_eq

AWOL

Quote
I may've missed it

You have.
Reply #6.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up