473,385 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

API design question

Hi all,

I'm working on a small embedded system (think microcontroller with uC/OS-II)
and I'm considering which convention to use for error handling in our
internal "API". Since I'm using two existing APIs (a low-level HAL and the
OS API) I already have mixed conventions since some return 0 for failure,
some return 0 for "no-error", etc.

I'm leaning toward the following basic rules, please critique at will:

1) Functions return what's convenient instead of forcing into a common
return-code convention. I don't like to have to write two lines of code
instead of one when testing return codes.

a) Boolean functions return 1/0, therefore boolean functions are not allowed
to fail
b) I/O functions return number of bytes read/written. Return of zero
indicates end-of-file, negative return indicates error
c) Functions that can fail and return a value that can be positive, negative
or zero have to return the error via pointer-to-argument. That allows
putting the function call into an if-statement when looking for a specific
return value

2) Keep a global header file with a list of error codes (a la winerror.h).
OS and HAL error codes get mapped to our global error codes as needed.

a) all error codes are negative
b) error codes are scalar (no bitfields), multiple concurrent error codes
have to be resolved by a separate mechanism

3) Have a global error code that can be returned via global function (a la
GetLastError()).

a) successful completion of a function (generally) does not overwrite last
error
b) last error is kept per thread
Comments? Suggestions?

Thanks,
Andrew
Feb 21 '06 #1
2 1585

"andrew queisser" <andrew.queisser at hp com> wrote

I'm working on a small embedded system (think microcontroller with
uC/OS-II) and I'm considering which convention to use for error handling
in our internal "API". Since I'm using two existing APIs (a low-level HAL
and the OS API) I already have mixed conventions since some return 0 for
failure, some return 0 for "no-error", etc.

Comments? Suggestions?

There is no easy solution tot he problem of errors.

You need one type when debugging, another type when distributing beta type
code to users, and a third type when you know the code itself is robust but
input may not be.

Sometimes you want code to be reusable, and sometimes you wnat a centralised
list of error codes. You can't have both.

One mistake the designer of the standard libary made was not to have any way
of querying the line number of an input file from its file pointer.
That would be one recommendation if you are doing IO from scratch,
preseuming your input is text which could potentially be corrupted.
--
Buy my book 12 Common Atheist Arguments (refuted)
$1.25 download or $6.90 paper, available www.lulu.com
Feb 21 '06 #2
In article <dt**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com>,
Malcolm <re*******@btinternet.com> wrote:
One mistake the designer of the standard libary made was not to have any way
of querying the line number of an input file from its file pointer.
That would be one recommendation if you are doing IO from scratch,
preseuming your input is text which could potentially be corrupted.


hmmm, the number of times I've needed the input line number in a C program
is... ummm, small enough that I'm having a hard time recalling any
instances.

I've needed the input line number a number of times in perl, awk, ed and
sed, but very rarely in C.

What kind of programs do you find that this feature would be
a noticable advantage in? Is it mostly a matter of wanting reusable
code that doesn't have to know how the rest of the program is
keeping track of the line numbers ?
--
Programming is what happens while you're busy making other plans.
Feb 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Don Vaillancourt | last post by:
Hello all, Over the years as I design more database schemas the more I come up with patterns in database design. The more patterns I recognize the more I want to try to design some kind of...
9
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with...
2
by: Test User | last post by:
Hi all, (please excuse the crosspost as I'm trying to reach as many people as possible) I am somewhat familiar with Access 2000, but my latest project has me stumped. So, I defer to you...
6
by: rodchar | last post by:
Hey all, I'm trying to understand Master/Detail concepts in VB.NET. If I do a data adapter fill for both customer and orders from Northwind where should that dataset live? What client is...
17
by: tshad | last post by:
Many (if not most) have said that code-behind is best if working in teams - which does seem logical. How do you deal with the flow of the work? I have someone who is good at designing, but...
17
by: roN | last post by:
Hi, I'm creating a Website with divs and i do have some troubles, to make it looking the same way in Firefox and IE (tested with IE7). I checked it with the e3c validator and it says: " This...
6
by: JoeC | last post by:
I have a question about designing objects and programming. What is the best way to design objects? Create objects debug them and later if you need some new features just use inhereitance. Often...
0
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the...
19
by: neelsmail | last post by:
Hi, I have been working on C++ for some time now, and I think I have a flair for design (which just might be only my imagination over- stretched.. :) ). So, I tried to find a design...
8
by: indrawati.yahya | last post by:
In a recent job interview, the interviewer asked me how I'd design classes for the following problem: let's consider a hypothetical firewall, which filters network packets by either IP address,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.