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

Errors in the CCS Webpage code
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Gavin Pinto



Joined: 18 Oct 2009
Posts: 27
Location: Australia

View user's profile Send private message

Errors in the CCS Webpage code
PostPosted: Thu Feb 04, 2010 9:17 pm     Reply with quote

I believe there are a few errors in code below. So please verify my findings so I will send feedback to CCS official support later to correct the oversight. Since it is not from the examples folder provided with the compiler and does not violate posting guidelines, I posted it here. It is on a CCS webpage. If CCS or their moderator feels it violates posting guidlines or copyright, I will delete it.

The code is from the following URL

http://www.ccsinfo.com/content.php?page=flexconst

A more complex example that creates an array of pointers to constant strings:
Code:
 
ROM char *strings[] =
{
   "HELLO",
   "WORLD",
   "CONST",
   "STRINGS"
};

/*
Access the above const pointers
*/
ROM char *ptr;
while (i = 0; i < (sizeof(strings) / sizeof(const char *)); i++)
{
   ptr = strings[i];
   printf("%s", ptr);
}

_________________
Clear Logic


Last edited by Gavin Pinto on Thu Feb 04, 2010 11:34 pm; edited 5 times in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 04, 2010 9:25 pm     Reply with quote

In questions like this,

1. Post your PIC.

2. Post your compiler version. We don't remember your version
from your previous threads.

3. Post a test program that demonstrates the problem.

4. Completely say what your problem is. Don't make it a mystery.
Gavin Pinto



Joined: 18 Oct 2009
Posts: 27
Location: Australia

View user's profile Send private message

PostPosted: Thu Feb 04, 2010 9:34 pm     Reply with quote

PCM programmer wrote:


4. Completely say what your problem is. Don't make it a mystery.


Well just reading the code you should see some problems. I don't think a compiler is needed in the initial analysis.

Later we may look at the compiler output.
_________________
Clear Logic


Last edited by Gavin Pinto on Thu Feb 04, 2010 9:40 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 04, 2010 9:39 pm     Reply with quote

OK. Someone else can help on this thread.
Gavin Pinto



Joined: 18 Oct 2009
Posts: 27
Location: Australia

View user's profile Send private message

PostPosted: Thu Feb 04, 2010 9:43 pm     Reply with quote

PCM programmer wrote:
OK. Someone else can help on this thread.


Ok I will help with my own thread. Should the while not be a for loop?

Do you see any other problems with the way the code is written?
_________________
Clear Logic
mbradley



Joined: 11 Jul 2009
Posts: 118
Location: California, USA

View user's profile Send private message Visit poster's website

PostPosted: Fri Feb 05, 2010 12:00 am     Reply with quote

Some times we do not see things when they are in front of us, I can only assume PCM was looking for a pointer as to what we should be looking for.

Case in point, this code drove me nuts looking for my error:

if (fltMode == MODE_FAA) { procFAA(); )

even though it was in front of me, I didnt see it, so imagine that line mixed with other code.

I understand you had a question, but you did not post what you thought was wrong with it.

I am not trying to stir things up, I like it here. sometimes we just need more information.
_________________
Michael Bradley
www.mculabs.com
Open Drivers and Projects
Gavin Pinto



Joined: 18 Oct 2009
Posts: 27
Location: Australia

View user's profile Send private message

PostPosted: Fri Feb 05, 2010 12:17 am     Reply with quote

mbradley wrote:
Some times we do not see things when they are in front of us, I can only assume PCM was looking for a pointer as to what we should be looking for.

Case in point, this code drove me nuts looking for my error:

if (fltMode == MODE_FAA) { procFAA(); )

even though it was in front of me, I didnt see it, so imagine that line mixed with other code.

I understand you had a question, but you did not post what you thought was wrong with it.

I am not trying to stir things up, I like it here. sometimes we just need more information.


Well the simple code I posted above has more errors. Since it is meant to be a tutorial I hope someone helps verify what I found.
_________________
Clear Logic


Last edited by Gavin Pinto on Fri Feb 05, 2010 3:14 am; edited 1 time in total
Gavin Pinto



Joined: 18 Oct 2009
Posts: 27
Location: Australia

View user's profile Send private message

PostPosted: Fri Feb 05, 2010 2:48 am     Reply with quote

mbradley wrote:
Some times we do not see things when they are in front of us, I can only assume PCM was looking for a pointer as to what we should be looking for.

Case in point, this code drove me nuts looking for my error:

if (fltMode == MODE_FAA) { procFAA(); )


I am not trying to stir things up, I like it here. sometimes we just need more information.


The wrong brace (closing bracket) you used is easy to spot from miles away. We all make these mistakes. So I am not talking about that. Basically I am looking for good examples to cut and paste that test the new compiler features.

Also interested what they do at the lower level. Still waiting for responses to what other problems you notice with the code I posted.
_________________
Clear Logic


Last edited by Gavin Pinto on Fri Feb 05, 2010 3:07 am; edited 1 time in total
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

Re: Errors in the CCS Webpage code
PostPosted: Fri Feb 05, 2010 3:07 am     Reply with quote

Gavin Pinto wrote:
I believe there are a few errors in code below. So please verify my findings so I will send feedback to CCS official support later to correct the oversight.


If you had said what your findings were then you may have got some feedback. As it stands it looks like you are asking us to do your home work or for some reason are testing us!

e.g. Here is some code I have written, it has errors, can you find them ?

I didn't actually understand what you were doing until I visited that link. Your explanation is not very good.
Gavin Pinto



Joined: 18 Oct 2009
Posts: 27
Location: Australia

View user's profile Send private message

Re: Errors in the CCS Webpage code
PostPosted: Fri Feb 05, 2010 3:10 am     Reply with quote

Wayne_ wrote:
Gavin Pinto wrote:
I believe there are a few errors in code below. So please verify my findings so I will send feedback to CCS official support later to correct the oversight.


If you had said what your findings were then you may have got some feedback. As it stands it looks like you are asking us to do your home work or for some reason are testing us!

e.g. Here is some code I have written, it has errors, can you find them ?

I didn't actually understand what you were doing until I visited that link. Your explanation is not very good.


No not testing you. I already tried to compile the code and came up with errors. Just wish you could also test to verify my findings. That's all.

and if you are interested in the features the code tries to demonstrate.

if not interested than ignore this post.
_________________
Clear Logic
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

Re: Errors in the CCS Webpage code
PostPosted: Fri Feb 05, 2010 3:14 am     Reply with quote

Gavin Pinto wrote:
Wayne_ wrote:
Gavin Pinto wrote:
I believe there are a few errors in code below. So please verify my findings so I will send feedback to CCS official support later to correct the oversight.


If you had said what your findings were then you may have got some feedback. As it stands it looks like you are asking us to do your home work or for some reason are testing us!

e.g. Here is some code I have written, it has errors, can you find them ?

I didn't actually understand what you were doing until I visited that link. Your explanation is not very good.


No not testing you. I already tried to compile the code and came up with errors. Just wish you could also test to verify my findings. That's all.


We still don't know what your findings are other than "it came up with errors", you also stated that compilation wasn't required yet you compiled it and found errors. Different versions of compiler may return different errors so PCMs post is relevant.

Later you post that you thought the while should be a for and looking at it this seems to be correct but you also state there are other errors. What were they and are they relevant to your compiler version ?
Gavin Pinto



Joined: 18 Oct 2009
Posts: 27
Location: Australia

View user's profile Send private message

Re: Errors in the CCS Webpage code
PostPosted: Sun Feb 07, 2010 9:55 pm     Reply with quote

Quote:

Later you post that you thought the while should be a for and looking at it this seems to be correct but you also state there are other errors. What were they and are they relevant to your compiler version ?


Well

i< (sizeof(strings) / sizeof(constant char*)) is incorrect
_________________
Clear Logic
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Mon Feb 08, 2010 3:12 am     Reply with quote

I would say the line is correct but it does not compile in my version of the compiler:-

CCS PCM C Compiler, Version 4.058

If I remove the const type from the lilne it compiles OK.

for (i = 0; i < (sizeof(strings) / sizeof(char *)); i++)

I don't know if it works correctly, not setup to test it. the size of a const char * may be different to a char *. I doubt it though as the .lst file shows the correct value of 4.

.................... i = sizeof(strings) / sizeof(char *);
*
00AB: MOVLW 04
00AC: MOVWF 27
Gavin Pinto



Joined: 18 Oct 2009
Posts: 27
Location: Australia

View user's profile Send private message

PostPosted: Mon Feb 08, 2010 5:07 pm     Reply with quote

Wayne_ wrote:
I would say the line is correct but it does not compile in my version of the compiler:-

CCS PCM C Compiler, Version 4.058

If I remove the const type from the lilne it compiles OK.

for (i = 0; i < (sizeof(strings) / sizeof(char *)); i++)

I don't know if it works correctly, not setup to test it. the size of a const char * may be different to a char *. I doubt it though as the .lst file shows the correct value of 4.

.................... i = sizeof(strings) / sizeof(char *);
*
00AB: MOVLW 04
00AC: MOVWF 27


Firstly sizeof(char *) evaluates to 2

sizeof(strings) evaluates to 4

4/2=2

sizeof(ptr) evaluates to 4 if pointer is declared as char rom *ptr;

now 4/4 =1

char rom *ptr;

rom char * ptr; //ptr is stored in RAM, is a pointer to ROM
rom char rom * ptr; //ptr is stored in RAM, is a pointer to ROM
char rom * ptr; //ptr is stored in RAM, is a pointer to ROM

now compare to following

const char* ptr1; // Ptr1 is a pointer to read-only RAM and is 2 bytes
char const* ptr1; //Ptr1 is a pointer to read-only RAM and is 2 bytes


Compiler version used 4.104 PCH
device is PIC18F8722
_________________
Clear Logic


Last edited by Gavin Pinto on Tue Feb 09, 2010 4:51 pm; edited 1 time in total
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Tue Feb 09, 2010 3:23 am     Reply with quote

Well, my compiler works differently to yours.

Sizeof(strings) = 8; // This is a pointer array. Each index contains a pointer to the string which is sizeof(char *) 2 bytes. so strings is 8 bytes in size.

sizeof(char *) = 2;

From the lst file
Code:

.................... a = sizeof(strings);
*
00AB:  MOVLW  08
00AC:  MOVWF  27
.................... b = sizeof(char *);
00AD:  MOVLW  02
00AE:  MOVWF  28
.................... i = sizeof(strings) / sizeof(char *);
00AF:  MOVLW  04
00B0:  MOVWF  29


The fomula
i = sizeof(strings) / sizeof(char *); returns 4 which is the number of null terminated strings in the pointer array strings. Which is correct.

Show me your .lst code where
"sizeof(strings) evaluates to 4"
Or did you work it out some other way ?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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