- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Recently I have been scouring the web looking for examples on a particular project (C based).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As teaching my customers "Programming" I always urge them to develop a coding standard for their companies. Since there is no global or ultimative standard and the coding rules have to be accepted by all members the best will be if the rules are developed by the members.
I teach that the main goal for a coding standard is to increase the readability of the code to its maximum. This measure will always reduce costs and will ensure a long project-lifetime. How this goal is enforced is always the company's selection. For each of the items a coding standard consists of there are different solutions and there might be a "best" one, but this often is a matter of taste.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks very much for the replies folks...
I started this thread as I think it may be useful, hence the breadth of my first post.
The "C" pdf is very useful, thanks Dana. (I believe I have a copy of the original version... somewhere)
Three cheers Bob, I agree 100%. The software I have to update today I first wrote in 1980 something, fortunately I had included 'reasonable' comments and descriptions !!
Now, a full 26 years later, I can justify the extra project costs at the time.
So on to my query,, is the 'extern' keyword useful/needed ?
I need to use a few globals (sorry, I like them) within a psoc tcp routine I am tinkering with.
But looking at forum code samples I find few reference to same.
Perhaps psoc creator could have a plugin that checks both the layout and design guides.
Many thanks, Michael.
p.s. second try with formatting.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks very much for the replies folks...
I started this thread as I think it may be useful, hence the breadth of my first post.
The "C" pdf is very useful, thanks Dana. (I believe I have a copy of the original version... somewhere)
Three cheers Bob, I agree 100%. The software I have to update today I first wrote in 1980 something, fortunately I had included 'reasonable' comments and descriptions !!
Now, a full 26 years later, I can justify the extra project costs at the time.
So on to my query,, is the 'extern' keyword useful/needed ?
I need to use a few globals (sorry, I like them) within a psoc tcp routine I am tinkering with.
But looking at forum code samples I find few reference to same.
Perhaps psoc creator could have a plugin that checks both the layout and design guides.
Many thanks, Michael.
p.s. second try with formatting.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Regarding the "extern" declaration of variables.
One step in designing a program-system (project) is the "modularization". This is the work of Isolating functional parts of the program ang writing a .h and a .c file for them. This step is essential for reducing company costs end ensuring maxmal error-free projects. The .h-file is then #included into the project or a library is built from the .c-file. Both ensure a common single codebase that can be re-used in every project that requires it.
Like global vars, the skope (visibility) of an extern var starts at the point of declaration and lasts to the end of the file. Of course it is possible to define functions that return the required item, but to save code and to avoid side-effects it can be easier to have an external variable defined. This should be done (of course) in the .h-file to avoid "forgotten" storage-classifiers as "volatile".
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I had a project using HiTech in PSOC 1 where I was severly crippled
and limited in code space size. Resorting to Globals and the use of
pointers to them saved the day, yielded 4K of additional FLASH space.
Largely associated with doubles in 8 bit processor.
Point is there are two sides to every coin. And there are associated
costs using local vs global as Bob points out. Always examine cost
benefit of doing something, sometimes the flip side of the coin more
beneficial.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks again for taking the time to reply folks.
I have noticed some "style" editors/formatters are available on the web, perhaps that could be a positive additon to PSoC Creator. (or a plugin)
Cypress seem to have it well sorted, when one reads the 'generated source code'.
Regards Michael.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A coding standard is nothing you could burden a program on, a coding standard has to be mended by us programmers
Compare the writings of
while(condition);
while(condition) Wait();
for(;;;)
while(forever)
a = x1/xx1 * d;
Vout = Vmeasure / Vref * TotalGain;
No software can do that!
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Interesting topic and something I've given a lot of thought to over the years as well. I've gone back and forth a lot. Currently, in the case of global variables, I use them in very limited situations. For example, I have some custom code that I added to the UART RX interrupt to set some global flags. I wouldn't want to be calling functions from an interrupt just to set a flag. In this case, I didn't even define the extern in the .h, but rather only in the UART's INT.c file. Even in this case, where it is reasonable to use global variables, it still sticks in my craw a little.
I get a bit obsessed sometimes about formatting. Just yesterday I caught myself "fixing" the brace after an if statement by moving it up to the same line as the if. Then I realised that it was Creator generated code that I was "fixing". Unfortunately, I don't have company-wide rules to fall back on. I try to be consistent, but it can be hard when you are a "maximizer".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have also been playing with UniversalIndentGUI, an interesting program...