Googles appar
Huvudmeny

Post a Comment On: cbloom rants

"03-16-13 - Writing Portable Code Rambles"

5 Comments -

1 – 5 of 5
Blogger super friend said...

Unfortunately I have a good amount of experience in porting code. I like many of the things you say in #1, such as the platforms, platform groups, and not ever allowing fallback cases.

I think something like

FUNC_PUBLIC_BODY( int , myfunc , (int args) )
{
FUNC_PUBLIC_PRE


is overkill. You can go this route of trying to turn everything into a macro language and it will make your code ugly and unwieldy. (Anytime someone starts to really heavily rely on the C preprocessor instead of a language I suspect something is wrong).

For 2 and 3, you may have a different perspective than I because I am more of an application programmer and I believe you are writing libraries, but I think that is too many levels. I would tend to forget about 2 and just use something that is more or less 3. I think with 2 and 3 you will end up with convoluted code that ends up doing unnecessary work on some or all platforms. If you support the operations in 3, and are free to code longer sequences of platform-specific operations in a platform-idiomatic way, the code will be clearer and more efficient.

In reality making a set of hard and fast rules about multiplatform programming may be futile. There's no substitute for good taste and professional judgement about each situation.

March 19, 2013 at 11:21 AM

Blogger cbloom said...

Well at a minimum you need private/public and the two-piece func markups (for visibility, dlls, linkage, calling convention, etc). So the alternative is something like :

FUNC_PRIVATE1 int FUNC_PRIVATE2 myfunc( int args )
{
}

that's what I'm using right now, and it's ugly enough that I figure going to

FUNC_PRIVATE( int, myfunc, (int args) )

is not really worse and is even more flexible.

March 19, 2013 at 11:32 AM

Blogger cbloom said...

This isn't really a porting issue, but a related thing that I might consider doing at the same time if I was to redo everything is to have macros for all the function args in the preamble, like :

{
ARGCHECK( arg1, 0, 10 , return false );


}

which takes the valid range and what to do if the arg is out of range. That macro might not necessarily compile into an arg check; sometimes it might just be an assert on the arg range; in some modes it might log the args so you have full call tracing with arg values.

March 19, 2013 at 11:35 AM

Anonymous Anonymous said...

You said:

"I would also go ahead and add my own asserts for args and returns in this layer, because I"

The anticipation is killing me. Because you ???

March 30, 2013 at 8:57 AM

Blogger cbloom said...

Ha, totally lost train of thought there.

Funny timing too because I just wrote a post about those kind of wrappers and stopping un-continuable error returns.

March 30, 2013 at 9:23 AM

You can use some HTML tags, such as <b>, <i>, <a>

This blog does not allow anonymous comments.

Comment moderation has been enabled. All comments must be approved by the blog author.

You will be asked to sign in after submitting your comment.