Pages: [1] 2 3 ... 5   Go Down
Author Topic: Not TRYING to start a flame war honest.  (Read 5160 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Edison Member
*
Karma: 30
Posts: 2494
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

eg...

Code:
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?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 638
Posts: 50300
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...)
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 31
Posts: 887
Old, decrepit curmugeon
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged

New true random number library available at: http://code.google.com/p/avr-hardware-random-number-generation/

Current version 1.0.1

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26495
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

Offline Offline
Edison Member
*
Karma: 30
Posts: 2494
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


scary smiley-grin
Logged

Leeds, UK
Offline Offline
Edison Member
*
Karma: 80
Posts: 1729
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have used this before:

Code:
#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:
#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);
}

« Last Edit: August 15, 2012, 09:46:57 am by Tom Carpenter » Logged

~Tom~

Ayer, Massachusetts, USA
Offline Offline
Edison Member
*
Karma: 54
Posts: 1857
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Edit:
or you can do this one for bitwise operators:
Code:
#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.
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 159
Posts: 2916
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#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.
Logged

Ayer, Massachusetts, USA
Offline Offline
Edison Member
*
Karma: 54
Posts: 1857
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4813
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Code:
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.
Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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'. smiley
Logged

I only provide help via the forum - please do not contact me for private consultancy.

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 74
Posts: 2214
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Offline Offline
Edison Member
*
Karma: 30
Posts: 2494
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Code:
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:
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?
Logged

Des Moines, WA - USA
Offline Offline
God Member
*****
Karma: 25
Posts: 779
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: August 16, 2012, 12:15:45 am by lloyddean » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26495
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I may've missed it
You have.
Reply #6.
Logged

"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.

Pages: [1] 2 3 ... 5   Go Up
Jump to: