Yes - in X code, we use these macros to allow compiling with gcc,
Sun Studio, or other compilers:

#if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 303)
# define _X_EXPORT      __attribute__((visibility("default")))
# define _X_HIDDEN      __attribute__((visibility("hidden")))
# define _X_INTERNAL    __attribute__((visibility("internal")))
#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
# define _X_EXPORT      __global
# define _X_HIDDEN      __hidden
# define _X_INTERNAL    __hidden
#else /* not gcc >= 3.3 and not Sun Studio >= 8 */
# define _X_EXPORT
# define _X_HIDDEN
# define _X_INTERNAL
#endif

It does require making sure the macro is used at the beginning of
the declaration as Sun Studio requires, instead of the end as gcc
allows, but you can write code acceptable to both like this:
_X_HIDDEN int
xf86KbdOn(void)
{
...

You can also just use linker mapfiles with all compilers as well,
but that may not be as portable to other OS'es.

        -Alan Coopersmith-           alan.coopersmith at sun.com
         Sun Microsystems, Inc. - X Window System Engineering

Alfred Peng wrote:
> Hi guys,
> 
>     I've got a problem about C extension from gcc. Hope that you can
> give some advices.
> 
>     Gcc provides an extension that programmer can declaring attributes
> of functions. The visibility attribute on ELF targets causes the
> declaration to be emitted with default, hidden, protected or internal
> visibility. And "hidden" visibility indicates that the symbol will not
> be placed into the dynamic symbol table, so no other module (executable
> or shared library) can reference it directly. Is there a similiar
> functionality provided by Suncc compiler?
> 
> Thanks,
> 
> -Alfred
> _______________________________________________
> tools-linking mailing list
> tools-linking at opensolaris.org


Reply via email to