Hi Zdenek,

On Friday 27 July 2012 16:48:23 Zdenek Bouska wrote:
> POSIX functions defines at the end of uspace/lib/posix/unistd.h
> conflicts with properties with same name.
> 
> I have modified it [1] to avoid this by changing
> #define truncate posix_truncate
> to
> #define truncate(...) posix_truncate(##__VA_ARGS__)
I think this not good workaround either, as a valid posix program may use a 
code similar to your workaround, like this:

int the_answer = 42;
if (the_answer == 42) {
    used_fn = &fn;
}
else {
    used_fn = &my_custom_fn;
}
used_fn();

Before the change in 1547, the code would call posix_fn, whereas now it would 
call fn.

> Problem is now only with function pointer properties of same name:
> 
> fs->op.truncate(path, size);
> 
> I can't think of a way how to avoid this conflict other than following
> ugly workaround. Can you?
> 
> int (*truncate_func) (const char *, posix_off_t);
> truncate_func = fs->op.truncate;
> truncate_func(path, size);
Another workaround is to undefine the macro temporarily, but it is probably 
even more ugly:
#undef truncate
fs->op.truncate(path, size)
#define truncate posix_truncate

or

#pragma push_macro("truncate")
#undef truncate
fs->op.truncate(path, size)
#pragma pop_macro("truncate")

Anyway, I think the proper solution is to correctly replace function names in 
the sources that need the substitution to occur, but I can't think of a way to 
achieve this using the C preprocessor. Maybe we could use a wrapper around the 
C preprocessor to add the posix_ prefix where necessary instead of adding it 
using defines?

Regards,
Martin Sucha


_______________________________________________
HelenOS-devel mailing list
[email protected]
http://lists.modry.cz/cgi-bin/listinfo/helenos-devel

Reply via email to