LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 10-18-2005, 09:07 PM   #1
George2
Member
 
Registered: Oct 2003
Posts: 354

Rep: Reputation: 30
A strange usage of # and sizeof.


Hello everyone,


I have found a very strange usage of # and sizeof in the following statement,

Code:
#define FOO(p) static const struct_goo p = { .length = sizeof(#p "\n")};
What means "#p"? What is the meaning of the parameter -- #p "\n" -- passed to sizeof?


thanks in advance,
George
 
Old 10-18-2005, 10:39 PM   #2
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
#p puts whatever p is within double quotes. sizeof(#p "\n") would be sizeof("bar" "\n") with FOO(bar). Then "bar" and "\n" are concatenated by the compiler.
 
Old 10-19-2005, 12:11 AM   #3
George2
Member
 
Registered: Oct 2003
Posts: 354

Original Poster
Rep: Reputation: 30
Thanks primo,


Quote:
Originally posted by primo
#p puts whatever p is within double quotes. sizeof(#p "\n") would be sizeof("bar" "\n") with FOO(bar). Then "bar" and "\n" are concatenated by the compiler.
I have understood your points.


regards,
George
 
  


Reply



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
Strange behavior on sizeof(class) The_Nerd Programming 3 10-10-2005 12:22 AM
getting realtime info on memory usage-cpu and harddrive usage steering Linux - Newbie 5 03-03-2005 08:43 PM
Strange tar usage problem through Perl Darthlord Programming 0 09-02-2004 09:46 AM
how to determine cpu usage, memory usage, I/O usage by a particular user logged on li rags2k Programming 4 08-21-2004 04:45 AM
sizeof() and C/C++ boku Programming 2 09-01-2002 07:31 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:50 PM.

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