Re: Please help with __attribute__ weak
Dimitry Golubovsky wrote: > I need to declare a symbol which is weaker in the executable than in any > external static or dynamic library. > In other words, the executable provides some fallback function > implementation (in my example, for "write"). But if the linker or > dynamic linker resolves it, the symbol definition from an external > library must be used. H. J. Lu wrote: The weak symbol is different from the normal one only during creating executable or shared library if it is in a relocatable file. You can't use weak symbol for your purpose. But you can mark your symbol in shared library protected. = Well, libraries are not created by me, so I cannot rely on any possibility to mark symbols in it. Besides, this is for an automated tool which may deal with tens of functions at once (this is for a Haskell FFI generator known as `hsffig' that I am developing). If there is no way to declare overridable symbols in executables, then perhaps placing all those fallback stub functions in a separate static library (.a) and telling the linker to use it last (after all default and user-specified libraries) could do the job, couldn't it? This is less desirable though, as it complicates the linker command line, but if there is no way to do this via declaration in C code, I'll go with the library. -- Dimitry Golubovsky Anywhere on the Web
Please help with __attribute__ weak
I need to declare a symbol which is weaker in the executable than in any external static or dynamic library. In other words, the executable provides some fallback function implementation (in my example, for "write"). But if the linker or dynamic linker resolves it, the symbol definition from an external library must be used. I use: __f_write_weak_alias(int __fd, __const __ptr_t __buf, size_t __n) __attribute__((weak, alias ("write"))); /* alias declaration */ int write(int __fd, __const __ptr_t __buf, size_t __n) { printf("Abort\n"); } /* fallback implementation */ But even though "write" is resolved, calling the __f_write_weak_alias just prints "Abort" i. e. the symbol "write" was not overridden by the library definition. What is the right way to do this? Thanks for any advice. Dimitry Golubovsky Middletown, CT
Offset and Bit Mask for Bit Fields?
Hi, If one wants to automatically determine offset of a regular field in a C structure, one uses `offsetof' According to the documentation, == This macro (offsetof) won't work if member is a bit field; you get an error from the C compiler in that case. == Do there exist any means in gcc to measure offsets (of enclosing integer field) and bit mask for bit fields? If not, any chance to add them in the future? -- Dimitry Golubovsky Anywhere on the Web
Re: gcc for syntax check only (C): need to read source from stdin
Zack, Now this works. Thanks a lot. And with -pipe, no temporary files at all (checked -v output). Could this be possibly placed in some FAQ? I tried to google for this first but did not get such a definitive (and simple) answer. On 4/12/05, Zack Weinberg <[EMAIL PROTECTED]> wrote: > In order to run the compiler as well, you have to tell it what > language it's getting, e.g. > > $ cat a.c | gcc -x c -fsyntax-only - > > Normally this is determined from the file extension, but that's not > available when reading stdin. It doesn't matter (much) when running > the preprocessor, which is why it lets you do that without the -x c. > > zw > -- Dimitry Golubovsky Anywhere on the Web
Re: gcc for syntax check only (C): need to read source from stdin
Devang, Thanks for your relpy. This addresses only compiler's action problem (no output produced), but does not address the stdin problem. When I try % cat a.c | gcc -fsyntax-only - I get gcc: -E required when input is from standard input again and when I use -E it only runs the preprocessor, nothing else. i. e. gcc still does not want to do anything beyond preprocessing using stdin as input. On 4/12/05, Devang Patel <[EMAIL PROTECTED]> wrote: > Try -fsyntax-only -- Dimitry Golubovsky Anywhere on the Web
gcc for syntax check only (C): need to read source from stdin
Hi, A program I am working on generates some C code on the fly, and I would like to check its syntax right after generation. I might save this code fragment in a temporary file and gun gcc -c over it, watching for exit code (0: syntax OK, 1: incorrect). This is fine with the one exception that I have to create temporary files and then clean them up. Does there exist any way to accompilsh this with pipes entirely? Output object file may be discarded: I don't need it. Or I might even use -S option to only assemble, but again, output must be stdout, not a file (or /dev/null which does not work either: the last program in the pipeline tries to CREATE it, not to write into it, and fails). Looking for verbose output from gcc -v -pipe ... I noticed that all the components (cpp, cc1, as) are pipe-connectable (at least in most cases). It is only the gcc (driver) which says e. g. gcc: -E required when input is from standard input which limits me to using preprocessor as a pipe only. I am afraid direct invocation of cc1 may not be good because I have no idea how its command line options are stable across various versions of gcc. Does there exist an alternative driver/script doing same job as the "stock" gcc, but allowing piping its input and output? Thank you. -- Dimitry Golubovsky Anywhere on the Web