CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

What am I doing wrong?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
smackaay



Joined: 03 Jul 2008
Posts: 3

View user's profile Send private message

What am I doing wrong?
PostPosted: Thu Jul 03, 2008 12:42 pm     Reply with quote

I'm new to this particular C compiler and I'm curious why I can't seem to reliably compile.
Every time I try and compile the following piece of code, it gives me the error "A numeric expression must appear here" when trying to declare a variable. It highlights any variable declaration beyond the mass of initialization functions.

here's the code
Code:
#include "C:\Rotary Viscometer\pcwsource\pwm.h"


void main()
{
   int a;
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
   setup_oscillator(OSC_8MHZ);
   a=1; //Why I hav e to do this??!?!?!?
   
   
   
   int PWMFill;
   
   while (1)
      {
     
     
      }

}


As you can see, I'm just playing around so far, but this problem really bugs me. I was able to quell the error when I put the declartion of 'a' at the beginning and place an 'a=1;' afterwards but declaring the variable afterwards still doesn't work.

What am I doing wrong?
smackaay



Joined: 03 Jul 2008
Posts: 3

View user's profile Send private message

AAAARGH! it still makes no sense
PostPosted: Thu Jul 03, 2008 1:32 pm     Reply with quote

I've totally removed anything that could cause a problem!!!!

Code:
int initialize();

void main()
{
   int a;
   a=initialize();
   
   int b; //<----Error's here!
   b=1;
   
}

int initialize()
{

   return 0;
}



It still hangs when I declare anything after the function call!!! why!!!?!?!?! it doesn't recognize b as a variable and it says "Error 51, a numeric expression must be placed here" at "int b;"

I don't understand!!!! what am I doing wrong, if anything. Anyone seen anything like this?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 03, 2008 1:37 pm     Reply with quote

Don't put variable declarations in the middle of your code. Put them
at the beginning of your functions, including main(). Then, all your
problems will go away.
smackaay



Joined: 03 Jul 2008
Posts: 3

View user's profile Send private message

PostPosted: Thu Jul 03, 2008 1:39 pm     Reply with quote

Oh, ok, thanks. kind of a weird rule for C. but cool, thanks! It was the source of a great deal of frustration.
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Fri Jul 04, 2008 1:57 am     Reply with quote

Actually it has always been the case for C to have variable declarations at the start of a block {...}. Only when C++ came along did they allow for declarations to be placed anyware, including within loop declarations:-

for (int i=0; i<10; i++) {...}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group