Sponsored Content
Top Forums Programming Help me to understand strange 'typedef ... ' in some source... Post 302983612 by jim mcnamara on Thursday 13th of October 2016 09:51:09 PM
Old 10-13-2016
That is a typedef of a function. In this case the need was for portability -windows compiler versus maybe a linux C compiler.
No dataype declaration for the function. So, by default, the function will compile probably with a warning as a function that returns an integer.

So you do not worry about the platform, you will notice void * arguments. This lets you call COMPARE_ADDR with any datatypes as long as those datatypes are by reference (address of the object). It does not have a datatype for the function return. This kind of function typedef is usually done for situations where you want to call something to get a standard result, but windows and linux (example platform) do not have the same name for the function, but it may return { <0, 0, >0} for less than, equal to, or greater than.

Pretend example
Code:
#ifdef WIN32 
   COMPARE_ADDR=isequal;
#else
   COMPARE_ADDR=addr_foo;
#endif
/* see if the memory location of two variables is the same */
if  ( ! COMPARE_ADDR( &variable3, &variable1) {  /* if equal barf */
    errno=EINVAL;  /* invalid value error code */
    perror("Cannot continue, variables are identical and must not be identical\n");
    exit(1);   /* end program here */
}


Last edited by jim mcnamara; 10-13-2016 at 11:00 PM..
 

9 More Discussions You Might Find Interesting

1. Solaris

Conflicting 'typedef' error - Which gcc switch to use?

I am using gcc3.3.5 on solaris2.7. Its a 64 bit compilation I am compiling a file 'plugin.cpp'. It includes mach.h and the complation gives the following error. ----------------------------------------------------------------- mach.h error: conflicting types for `typedef vx_u32_t... (0 Replies)
Discussion started by: amitc
0 Replies

2. Programming

How to typedef

I want to declare char ch as ch_9 with the help of the typedef statement. Thanks (1 Reply)
Discussion started by: krishna_sicsr
1 Replies

3. Shell Programming and Scripting

bash shell: 'exec', 'eval', 'source' - looking for help to understand

Hi, experts. Whould anybody clear explay me difference and usage of these 3 commands (particulary in bash) : exec eval source I've tryed to read the manual pages but did not get much. Also could not get something useful from Google search - just so much and so not exactly, that is... (3 Replies)
Discussion started by: alex_5161
3 Replies

4. Programming

typedef struct forward declaration

I've google a bit about this and couldn't find an answer. Actually I read that it can't be done. Basically I've defined the following structure and typedef it as follows. stuct Name { }; typdef struct Name Name. and right after it, defined some API that use it. void blabla(Name*... (6 Replies)
Discussion started by: emitrax
6 Replies

5. Programming

Need help with this c++ source code! DOnt understand what some stuff mean.

Okay so I am just starting programming c++. I just started started to red "C++ for Dummies yesterday and theres a lot of things I do not understand from this book and this source code especially. I will first post the full source code and then post questions about certain thing, usually what they... (2 Replies)
Discussion started by: orszhak
2 Replies

6. Programming

typedef help

Hi! This is part of my my code : typedef struct{ int x; char na; char sur; } Stu; typedef struct{ Stu *arr; int size; int sort; } Stus; I want to ask how can i free() the matrix arr. I tried free(arr), free(Stus.arr) and i get errors with gcc. My problem, in... (3 Replies)
Discussion started by: giampoul
3 Replies

7. Programming

Compilation problem with typedef

I am getting confused compiling a program that gives me the following error ../../../tomso/algeb/vector.hpp:19:9: error: ‘Vector' does not name a type typedef Vector<float> Vecflt; (1 Reply)
Discussion started by: kristinu
1 Replies

8. Programming

Event driven programming / epoll / typedef union / session data array

Sorry for the “word salad” subject, but I wanted to cast a wide net for help. I've created an IP (Internet Protocol) server which serves HTTP, SMTP, and FTP requests. As you probably know, they all require creating a socket, listening on it, accepting connections, and then having a short... (3 Replies)
Discussion started by: John S.
3 Replies

9. Programming

Typedef does not work to name a type

Hello, This is related to the closed post in the forum for the installation of the same software called arachne, but with different error message: In file included from ueberal/MiniSuperizer.cc:5:0: ./random/GnuRandom.h:54:5: error: ‘_G_uint32_t’ does not name a type _G_uint32_t u; ^... (11 Replies)
Discussion started by: yifangt
11 Replies
NOTE(3EXT)						    Extended Library Functions							NOTE(3EXT)

NAME
NOTE, _NOTE - annotate source code with info for tools SYNOPSIS
#include <note.h> NOTE(NoteInfo); or #include<sys/note.h> _NOTE(NoteInfo); DESCRIPTION
These macros are used to embed information for tools in program source. A use of one of these macros is called an "annotation". A tool may define a set of such annotations which can then be used to provide the tool with information that would otherwise be unavailable from the source code. Annotations should, in general, provide documentation useful to the human reader. If information is of no use to a human trying to under- stand the code but is necessary for proper operation of a tool, use another mechanism for conveying that information to the tool (one which does not involve adding to the source code), so as not to detract from the readability of the source. The following is an example of an annotation which provides information of use to a tool and to the human reader (in this case, which data are protected by a particular lock, an annotation defined by the static lock analysis tool lock_lint). NOTE(MUTEX_PROTECTS_DATA(foo_lock, foo_list Foo)) Such annotations do not represent executable code; they are neither statements nor declarations. They should not be followed by a semi- colon. If a compiler or tool that analyzes C source does not understand this annotation scheme, then the tool will ignore the annotations. (For such tools, NOTE(x) expands to nothing.) Annotations may only be placed at particular places in the source. These places are where the following C constructs would be allowed: o a top-level declaration (that is, a declaration not within a function or other construct) o a declaration or statement within a block (including the block which defines a function) o a member of a struct or union. Annotations are not allowed in any other place. For example, the following are illegal: x = y + NOTE(...) z ; typedef NOTE(...) unsigned int uint ; While NOTE and _NOTE may be used in the places described above, a particular type of annotation may only be allowed in a subset of those places. For example, a particular annotation may not be allowed inside a struct or union definition. NOTE vs _NOTE Ordinarily, NOTE should be used rather than _NOTE, since use of _NOTE technically makes a program non-portable. However, it may be inconve- nient to use NOTE for this purpose in existing code if NOTE is already heavily used for another purpose. In this case one should use a different macro and write a header file similar to /usr/include/note.h which maps that macro to _NOTE in the same manner. For example, the following makes FOO such a macro: #ifndef _FOO_H #define _FOO_H #define FOO _NOTE #include <sys/note.h> #endif Public header files which span projects should use _NOTE rather than NOTE, since NOTE may already be used by a program which needs to include such a header file. NoteInfo Argument The actual NoteInfo used in an annotation should be specified by a tool that deals with program source (see the documentation for the tool to determine which annotations, if any, it understands). NoteInfo must have one of the following forms: NoteName NoteName(Args) where NoteName is simply an identifier which indicates the type of annotation, and Args is something defined by the tool that specifies the particular NoteName. The general restrictions on Args are that it be compatible with an ANSI C tokenizer and that unquoted parentheses be balanced (so that the end of the annotation can be determined without intimate knowledge of any particular annotation). ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |Safe | +-----------------------------+-----------------------------+ SEE ALSO
note(4), attributes(5) SunOS 5.11 31 Dec 1996 NOTE(3EXT)
All times are GMT -4. The time now is 07:43 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy