Pages: [1] 2   Go Down
Author Topic: many errors when compiling the C program  (Read 1031 times)
0 Members and 1 Guest are viewing this topic.
universe
Offline Offline
Sr. Member
****
Karma: 0
Posts: 258
I'm enjoying my Life
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm newbie in C programming and i am trying to drive my arduino, but I found there errors:

sketch_mar05d:84: error: expected constructor, destructor, or type conversion before '=' token
sketch_mar05d:85: error: expected constructor, destructor, or type conversion before '=' token
sketch_mar05d:86: error: expected constructor, destructor, or type conversion before '=' token
sketch_mar05d:87: error: expected constructor, destructor, or type conversion before '=' token
sketch_mar05d:88: error: expected constructor, destructor, or type conversion before '=' token
sketch_mar05d:92: error: expected constructor, destructor, or type conversion before '(' token
sketch_mar05d:93: error: expected constructor, destructor, or type conversion before '(' token
sketch_mar05d:94: error: expected constructor, destructor, or type conversion before '(' token
sketch_mar05d:97: error: expected unqualified-id before 'for'
sketch_mar05d:97: error: expected constructor, destructor, or type conversion before '>' token
sketch_mar05d:97: error: expected constructor, destructor, or type conversion before '--' token

here is the code: http://physicsforums.com/showthread.php?t=583892
I'm sorry I cant post he code all here because words limitation.

Thank you before
Logged

Cleveland, TN
Offline Offline
Full Member
***
Karma: 2
Posts: 207
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I haven't seen Gosub used in many many years and not in Arduino so I can't tell what might be wrong there except that they simply might not work in v1.0 I did notice you use if/endif instead of if {  }. I'm not sure if this syntax works in the IDE or not. In traditional C if loops, an equal to comparison is done with a double ==. This may or may not be causing problems as well since I am unfamiliar with using a VB style if/end if syntax in the arduino IDE.

I did notice some missing ';'.

  g_pinCommLatch1=LOW
  g_pinCommLatch2=LOW
  g_pinCommLatch3=LOW

Every one of the errors you are getting are related to a syntax error where you have fumble fingered something or left out something. Fix those 3 and see if it starts to shorten your list.

Did you copy this code from somewhere or write it yourself?

I only ask because this is A LOT of code to not have built many times to catch these types of errors in pieces instead of catching all the errors in one build which makes it much more difficult to track down the problems.
Logged

Luck,

Wade

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Code:
Tombol:
  GoSub Blinks
 
  if switchPin1=1 and a=1 then
  GoSub Counter1
  a=0
  elseif switchPin1=0 and a=0 then
  a=1
  end if

  if switchPin2=1 and b=1 then
  GoSub Counter2
  b=0
  elseif switchPin2=0 and b=0 then
  b=1
  end if
 
  if switchPin3=1 and c=1 then
  GoSub Counter3
  c=0
  elseif switchPin3=0 and c=0 then
  c=1
  end if

  if resetPin1=1 and a=1 then
  GoSub reset1
  end if

  if resetPin2=1 and a=1 then
  GoSub reset2
  end if
 
  if resetPin3=1 and a=1 then
  GoSub reset3
  end if

GoSub Show1
GoSub Show2
GoSub Show3
GoSub SendSerialData1
GoSub SendSerialData2
GoSub SendSerialData3
delay(1000
GoSub Tombol

It doesn't compile because this is Basic, not C.
Logged

universe
Offline Offline
Sr. Member
****
Karma: 0
Posts: 258
I'm enjoying my Life
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

To Sacman:
I write it by myself, by using the logic from my supervisor final project. I thought he used C language.
To Nick Gammon:
Oh thank you finally I know this is Basic, heu smiley-grin

To All:
Every arduino program, I have found that they use void(), it means it has no return value.
One reason why I force to use GoSub is because it has return value, and in my complicated program, I need to return..

Do you have any idea what syntax I can use in order to have return value? smiley-grin
Logged

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

Here is a short few texts on functions, parameters and return values.

http://cpp-tutorial.cpp4u.com/structures_functions.html
http://www.dummies.com/how-to/content/working-with-functions-in-c.html
http://www.cplusplus.com/doc/tutorial/
« Last Edit: March 05, 2012, 01:11:03 am by pYro_65 » Logged


universe
Offline Offline
Sr. Member
****
Karma: 0
Posts: 258
I'm enjoying my Life
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

To pYro_65:
But I'm working with C not C++,so?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To All:
Every arduino program, I have found that they use void(), it means it has no return value.
One reason why I force to use GoSub is because it has return value, and in my complicated program, I need to return..


Better start studying C++, I think. The Arduino IDE uses C++ (not C). Also only void functions return no value. To return a value you put some other word (like int) in place of void. eg.

Code:
int foo ()
  {
  return 42;
  }

In any case, functions return, whether or not they return a value.
Logged

universe
Offline Offline
Sr. Member
****
Karma: 0
Posts: 258
I'm enjoying my Life
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

To Nick Gammon:
Oh I think it uses C and not C++,thank you for your worth info, recommendation book to download for C++?

Can you give example in what part of the void I must put the 'int'?
And why you return 42? why not 43?where the return goes?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why 42? Why indeed ...

http://en.wikipedia.org/wiki/42_(Hitchhiker%27s_Guide_to_the_Galaxy)#Answer_to_the_Ultimate_Question_of_Life.2C_the_Universe.2C_and_Everything_.2842.29

As for the other questions, try Googling "C++ tutorial".
Logged

universe
Offline Offline
Sr. Member
****
Karma: 0
Posts: 258
I'm enjoying my Life
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

heuu, well I must start from beginning again for C++
Thank you all very very very very much, at least now I know where I should go rather than stay fixing crazy code now.
Logged

universe
Offline Offline
Sr. Member
****
Karma: 0
Posts: 258
I'm enjoying my Life
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

again i found problems starting to learn C++:

I write this code in my compiler Arduino IDE:

Code:
#include <iostream>
using namespace std;

int main ()
{
  cout << "Hello World!";
  return 0;
}

Then it show this:

sketch_mar05a.cpp:1:20: error: iostream: No such file or directory
sketch_mar05a.cpp: In function 'int main()':
sketch_mar05a:5: error: 'cout' was not declared in this scope

is it C or C++?or is there any wrong with the compiler?

Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Right. Well these examples assume you are running on a Unix or similar system where you have stdin and stdout. (That is, in effect, the keyboard and the screen). Since you don't have a keyboard or screen on the Arduino you have hit a problem.

Try looking at some of the example sketches in the IDE. For one thing, they "predefine" main for you, so even using main is a no-no.

Your sketch could be rewritten as:

Code:
void setup ()
  {
  Serial.begin (115200);
  Serial.println ("Hello, world");
  }

void loop () {}

To be more C++ like, you can use the streaming library from:

http://arduiniana.org/libraries/streaming/

Then your sketch can look like:

Code:
#include <Streaming.h>

void setup ()
  {
  Serial.begin (115200);
  Serial << "Hello, world" << endl;
  }

void loop () {}

In this case "Serial" behaves somewhat like "cout".
Logged

Cleveland, TN
Offline Offline
Full Member
***
Karma: 2
Posts: 207
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


AWESOME!!!

I turned 42 this year. So many people just don't get it when i tell them I am the answer to Life the Universe and Everything.
Logged

Luck,

Wade

universe
Offline Offline
Sr. Member
****
Karma: 0
Posts: 258
I'm enjoying my Life
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hmm, both codes you gave me is much different for newbie like me...
I think to save time, can I just directly learn the pattern for the IDE rather than C++ then convert to IDE C++...?

Hmmm, where I can learn C++ for Arduino IDE?
I'm so sorry coz I ask too many...
Logged

universe
Offline Offline
Sr. Member
****
Karma: 0
Posts: 258
I'm enjoying my Life
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote

AWESOME!!!

I turned 42 this year. So many people just don't get it when i tell them I am the answer to Life the Universe and Everything.

woo hooo! You are...
Logged

Pages: [1] 2   Go Up
Jump to: