Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-09-2005, 11:29 AM   #1
Registered: Feb 2004
Location: Athens, Greece
Distribution: Gentoo,FreeBSD, Debian
Posts: 705

Rep: Reputation: 30
c preprocessor commands & return types(?)

I don't think exactly, that C preprocessor commands-defines return something, but see that:
447 #define IW_EVENT_CAPA_INDEX(cmd)        (IW_EVENT_CAPA_BASE(cmd) >> 5)
448 #define IW_EVENT_CAPA_MASK(cmd)         (1 << (IW_EVENT_CAPA_BASE(cmd) & 0x1F))
Here is the IW_EVENT_CAPA_BASE(cmd) definition:
441 /* Event capability macros - in (struct iw_range *)->event_capa
442  * Because we have more than 32 possible events, we use an array of
443  * 32 bit bitmasks. Note : 32 bits = 0x20 = 2^5. */
444 #define IW_EVENT_CAPA_BASE(cmd)         ((cmd >= SIOCIWFIRSTPRIV) ? \
445                                          (cmd - SIOCIWFIRSTPRIV + 0x60) : \
446                                          (cmd - SIOCSIWCOMMIT))
when a preprocessor "define" uses bitwise operators on another preprocessor "define", surely the latter must return a value. How do i understand this value? In this occassion, it is of course an arithmetic one, but what kind (int, long, etc)?

Last edited by kpachopoulos; 11-09-2005 at 11:30 AM.
Old 11-09-2005, 12:08 PM   #2
Registered: Oct 2005
Location: Chicago, USA
Distribution: Slackware & Fedora
Posts: 66

Rep: Reputation: 15
These are just macros. There is no 'type' associated with the argument. It performs text substitution and the code is compiled. The resulting code will dictate type. This is why some macros are not safe when types are important.

For a simple answer, the 'type' is the same type as 'cmd'. If you pass a 64-bit integer, then the result will be based on that (by promoting all other arguments.) However, in this case, it seems that the operation is expecting 32-bit integers (platform-specific)! Using 64-bit will work for the arguments, because these two macros is just telling what 32-bit word (macro IW_EVENT_CAPA_INDEX) and what bit within this 32 bit word as a mask ( IW_EVENT_CAPA_MASK ). Just make sure that the variable accepting the MASK result is at least 32 bits.
Old 12-03-2005, 11:49 AM   #3
LQ Newbie
Registered: Dec 2005
Posts: 1

Rep: Reputation: 0
i jus have a question in mind whether char can be used as a return type in C
Old 12-04-2005, 02:15 AM   #4
Registered: Nov 2005
Location: Coimbatore,India
Distribution: Fedora Core4
Posts: 68

Rep: Reputation: 15
Why not?
And u should have started a separate thread if u wanted to get the response from all
Old 12-06-2005, 09:18 AM   #5
Registered: Oct 2005
Location: Chicago, USA
Distribution: Slackware & Fedora
Posts: 66

Rep: Reputation: 15
Any defined type can be used as a return type.
This includes all basic types:
unsigned char
unsigned long
unsigned short
unsigned int
void * (any kind of pointer works too)

Complex types including:
typedef enum { VAL_1, VAL_2, VAL_3 } MyEnum;

MyEmum AFunction( ... );
typedef struct my_struct { long a; char b; double c; } MyStruct;

MyStruct BFunction( ... );  /* <-- Using the typedef  */
struct my_struct BFunction( ... );  /* <-- Using the fully qualified name. */
unions (see struct above with union instead of struct)

All these return types can also apply the const qualifier. Pointers can have a pointer to what is pointed to and the pointer itself.

C++ offers three more possibilities: two types (bool and class) and references.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
PPP library & pppd, chat return codes ruchika Linux - Networking 1 03-08-2011 02:50 AM
Find & Replace Carriage Return in ooo linuxian Linux - Software 1 04-09-2005 05:43 PM
green types & black baclground text editor chunlee Linux - Software 10 06-18-2004 09:50 AM
Switching Between 'Modem' & 'LAN' Connection Types In Mandrake silburnl Linux - Networking 1 02-23-2004 07:01 AM
ALSA & mmap -- Return to Castle Wolfenstein The Burninator Linux - General 2 02-05-2004 06:47 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:37 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration