2017年10月18日 星期三

Gmail Filter

Reference:

http://raisedbyturtles.org/view-unlabeled-gmail


Why do we even want to find unlabeled emails?

I assume if you’ve arrived here, you already have your reasons. But you might be asking, why get so obsessive?
A couple of possible reasons:
  • You may want to do an import from another account or something like that. So you label everything currently in your account with “main” and then when you import, you find all unlabelled messages, label them “imported” and then delete the “main” label.
  • You just like every single thing to have a label because you’re that kind of person.
I’ll be honest — when I wrote this, I wanted everything to have a label. Why? Because in the past I had used clients like Thunderbird and Outlook that had the concept of folders, but not labels. The inbox is just a folder. So if you want to get something out of your inbox, it has to go in a different folder.

Gmail is different

Gmail is different. For one, the search function is really good. This means that I am more likely to look for something via search, than by drilling down through folders/labels.
In short, I do not ever use this method myself anymore. Instead, I have a manageable number of labels and a lot of filters. Most recurring emails get a label automatically and then I archive when needed. I  label things that I need for taxes or with a project name, but typically I have a filter that just applies the label. Then I depend on search. Automate what you can. Forget 90% of the rest.
That doesn’t mean people don’t have very good and compelling reasons for wanting to find unlabeled messages, but you might ask yourself whether or not you’re bringing an Outlook/Thunderbird mindset to a Gmail and just let it go.
I originally wanted everything labeled, but I was wrong. What I found was that I was better at remembering conversation keywords than I was at remembering labels and searching for conversation keywords is Google’s core competency. I decided that organizing my email manually was a waste of time and a study by IBM confirms this.
Yes, I have been assimilated by the Gorg!

Quick Version: GMail Filters for Finding Unlabeled Messages

This article has evolved a lot as Gmail evolved and I’ve tried to rationalize it a bit and get to the point (it was littered with dated “updates”). Here’s the short answer. If you want to understand what these filters mean, how we came up with them, or how to use them, scroll down for the original article which gives all the practical and theoretical background on custom Gmail filters.
All right already, show me the method!

Method 1 — Simple and mostly reliable

Still in June 2016 as I edit this, the best method currently seems to be to exclude anything that has custom labels or one of the standard built-in labels as follows (thanks Tony Franks for the comment from 2013-07-01):
-has:userlabels -in:sent -in:chat -in:draft -in:inbox
Ron Wolf suggests in the comments (Nov 29, 2016), to add -from:me to the search to avoid getting your own messages. I find these are the ones that often don’t get labelled and are the ones I’m searching for, but again, it all comes down to how you use Gmail.
You just enter these searches into the search box, click the Select All checkbox and then click the link to select all messages matching your search, as in the screenshot below (click to view full size):

Entering your search in Gmail to find unlabeled emails
You’ll notice that at the bottom of the screenshot, the last item is in the Inbox and should not get found. That’s part of a threaded conversation with multiple participants where people aren’t using Reply All. That seems to result in having Gmail see some of the subthreads with some participants as having been archived and meeting the search criteria. So it isn’t perfect.

Method 2 — Simple but not very reliable.

If that doesn’t work, you can try a method JonG posted on 2013-01-14. Unfortunately, that method seems to be flaky for many people and has never worked at all for me, but it does work for others:
has:nouserlabels -in:sent -in:chat -in:draft -in:inbox

Method 3 — highly reliable but a pain in the butt

My original method is more labor-intensive but at the time, the special “userlabels” pseud-label wasn’t available, so you had to laboriously build a search and save it for future use. This method is a pain in the neck, but works reliably precisely because it doesn’t really depend on any tags with special meaning. The key is that you can combine single-word labels in braces, but multi-word labels seem to need their own entry with the spaces replaces with dashes, like so:
-label:{label1 label2} -label:label-three -label:label-four -in:sent -in:chat -in:inbox
If you do this more than once, typing in all your labels in the arcane syntax Gmail uses gets old. So what I’ve done is simply create a shortcut, which you can do quite easily and it works up until you add a new label, but then it’s just a simple matter of editing the bookmark.

Method 4 — Desperate Measures

Finally, if all else fails, you can use this roundabout method from Federico (comment from 2013-06-08):
  • First search for every message that HAS a label (has:userlabels)
  • Label ALL of the results with a new “LABELED” label (or whatever you want)
  • Now search for has:nouserlabels
  • Ba Dum, you got them!
  • Delete your “LABELED” label.

Conversation Mode and labels

With all methods, Danimal suggests turning off conversation mode (threaded conversations) as that can make things confusing.
I like leaving conversation mode on because I generally want to catch only entire conversations with no labeled messages at all. If any message in the thread is labeled, that’s good enough because I’ll find the conversation via the label.
But if you want to find not unlabelled threads, but all unlabeled individual messages, then you need to do as Danimal says.

Details: Understanding GMail Filters

You have a full syntax and a compact syntax and, as far as I can tell, the compact syntax does not work with multi-word labels. So if you have Gmail labels with spaces in them, you have to use the full syntax and substitute hyphens for spaces.
So let’s say you have the following labels:
  1. Label1
  2. Label2
  3. Label Three
  4. Label Four
First, we want to exclude all messages that have those labels. To exclude a labeled message from your search, you use the -label: operator.
For the single-word labels, we’ll use the short syntax. This allows you to group terms within curly braces without repeating the “-label:” qualifier. So it looks like this in your Gmail search box
-label:{Label1 Label2}
Simple as that.

Multi-word labels are a bit more complex

Now for the multi-word labels, in theory, I merely need to add quotes around the terms, and they should work within the curly braces. Not so for me. If you create a filter and look at the test search, that’s not how it does it either. So based on that, what I found worked for Label Three and Label Four was:
-label:Label-Three -label:Label-Four
So the entire search, with both single-word labels and multi-word labels, looks like this
-label:{Label1 Label2} -label:Label-Three -label:Label-Four
Now, that will create a URL that looks like this
http://mail.google.com/mail/#search/-label%3A%7BLabel1+Label2%7D+-label%3ALabel-Three+-label%3ALabel-Four

Save your search for later use

Now you can save this as a bookmark or shortcut and instantly access your unlabeled Gmail messages. Sometimes Gmail will add a zx parameter to your URL that looks like zx=afeoasdxou3swf that is just a random string so that if your ISP is caching data, it will see this as a unique URL and won’t give you cached data for Gmail. Since this effectively creates a single-use URL, if that appears in your URL when you do your search, you should edit it out before saving the bookmark.
Note that if a message has two labels and you are only excluding one of those, the message will still show up in your search. So if you have something labeled Label1 and Label5, and you use the search above, it will still show up in your results.
Also, sometimes a conversation that is labeled shows up because one message is unlabeled or is still in the Inbox. If you select the whole conversation in the list view and label it, that takes care of that issue.

Additional Operators and Pseudo-Labels

As you saw above, there are additional operators (in and has) and special built-in pseudo-labels (userlabels).
Depending on what you are trying to do, you can shorten or refine your search by using in with any built-in label (inbox, trash, etc) and has with userlabels.
  • -in:inbox (don’t find anything if it’s still in the inbox)
  • in:trash (if you want to search the Gmail trash, you need a special operator because by default it’s excluded)
  • in:anywhere (lets you do a search that includes spam, trash, inbox and, well, messages found anywhere)
  • -has:userlabels should be the same as has:nouserlabels, but in practice people report that they are not.
There are tons more options. See the Google Gmail Label Documentation for a full and current list.

Labeling Your Backlog

As per Karen’s suggestion below (see comments), if you’re trying to identify your unlabelled email just once and label your backlog, then you can view All, apply a label like “NoLabel” to it (or move them all to the Inbox as Karen suggests).
Now go into every other label folder, select all and remove the “NoLabel” label (or Archive if you put them in the Inbox). Now if you go to the NoLabel folder, you have all your unlabelled email. If you’re going to do this on any kind of regular basis, though, you’ll want a bookmark as described above, otherwise this will be pretty time-consuming.

Dealing with Child Labels and Labels with Special Characters

James asks, what happens if you have special characters like underscores or slashes in your Gmail labels? If you are using the Gmail sublabel feature, you will automatically have slashes because Gmail separates parent and child labels with slashes (look at Gmail in the Basic HTML mode and you can readily see this). First off, most special characters are just entered as such. Slashes must be entered as hyphens.
So let’s say you have the following setup:
  • Main
    • test1
      • test2
    • test3/test4
    • test*,:-test-./test
In that case, your search syntax will be, respectively
  • -label:main
  • -label:main-test1-test2
  • -label:main-test3-test4
  • -label:main-test*,:-test-.-test
Note that a label called “test3/test4” which is a single label, behaves exactly the same as test2 which is a child label of test1. And for anything except slashes and spaces, which are both replaced by hyphens, you just use the character as it appears in the label. That’s even true for the colon, even though it’s part of the search syntax.

A Question for YOU (please read)

Did you really make it all the way to the end of that article? You have endurance and perseverance, which makes me think I can ask one little favor. Would you be so kind as to add a comment below or go to my contact page and tell me what trouble you have with email currently. What is your top email pain point? I’ve been giving a lot of thought to the topic over the last couple of years and am preparing some articles on the subject and would love to hear from you about what you would like help with or your best ideas for reducing the pain of email hell.
I guarantee that you will not get added to any mailing list and, in fact, your email address won’t even get saved except insofar as WordPress saves it with all comments and form submissions as a spam-fighting tool.

2016年5月10日 星期二

What are the characteristics of a bad software engineer? / 邁向頂尖開發者的道路上,你該避免成為下列十種討厭鬼

Reference:

https://www.quora.com/What-are-the-characteristics-of-a-bad-software-engineer/answer/Nachiket-Naik
http://www.inside.com.tw/2015/07/06/10-characteristics-of-a-bad-software-engineer


Nachiket Naik:
1) The Stack Overflow bot: This person ran into an error, did a quick Google search and applied the first solution they found. The problem here is not that of copying from Stack Overflow. I think there are more solutions on Stack Overflow than any reference guide or manual. Don't get me wrong, it's a wonderful resource, if not the best. The problem is the robotic application of it without understanding the consequences. The problem is the application of it without fully understanding the context of it and whether it really applies to the current problem at hand. More often than not, I have seen people believe more of what they see on online forums than the code/system in front of them.

2) The I-am-not-a-tester: I don't need to test the code; that is the job of the testers. I don't think that even in this age of mature Agile methodologies, this attitude has waned. There is still an inertia against testing their code. Part of it comes from lacking the interest to set up a testing environment and partly from lack of coherent knowledge of testing. (Is it also partly due to an unspoken stigma against testers in the developer community.)

3) The I-hate-documentation: Some people believe that code documentation must be poetic and hence they lack the skill to do it, ergo not their job. In my opinion, these are the #1 foes of sustainable software. Good software is not software that provides a million cool features. Good software is one that has a few good features that are used consistently by many people and read/updated/modified by a thousand. This brand of developers who believes less in technical communication and precise and detailed documentation is the greatest weed to a company's success.

4) The ugly: My code works, but:

  • I have variables named x, flag, str, arr, etc.
  • Most of what I write is in one giant method.
  • There is no indentation.
  • No consistent coding convention or style.
  • Global variables spewed all over the place, etc.
This is the most annoying thing for me personally. It's not the issue that the code is bad. It could potentially be the greatest piece of code written. But if a diamond necklace is buried in the debris of the Titanic, nobody will find it, and nobody will want to clean it, wear it, use it.

5) The short-term investor: He codes. He deploys. He moves on. No attempt to learn the problem. No interest in the domain. Just give this guy a piece of code, he will slog on it overnight and hand it over. You got a fix/working software. Nothing more achieved from it. Sometimes, it's important that you have certain selfishness in the developer, one who not only cares about the deadline, but also cares about what he/she got to learn from it.

6) The protester: "I didn't do this". "This looks bad". "Not my problem". "This isn't related really to my fix, but someone way over there made a mistake". "I hate this (loop this sentence 10 times a day)", "I can't fix this, get the person who made this code to fix it".
The person who coded that mistake has moved on, when will you?

7) The dictator: My way or the highway is their motto. It's their "ideas" vs "your ideas", not "project ideas". It's their solution vs your solution. I bet there will be an argument for sure. Somehow they will keep coming back to a part of code that you implemented. It somehow discomforts them even if it works, tests, and looks perfectly fine. This person is a big bottleneck to productivity and will be the first person to crumble under pressure and start pointing fingers. This person is not good for the team, however experienced/good a developer he may be.

8) The overcautious: The Java developer who just froze when he learned that he would have to write a Python script. The developer who panicked on learning that something in the registry needs changing. The developer who cringes at having to input things in the database. These people will do anything to avoid getting out of their comfort zone. They have weird superstitions related to having to touch certain parts of the system. I have learned, from personal experience, that this phenomenon is common with new developers. Good developers show a tendency to slowly/swiftly move out of their comfort zone in exploration.

9) The careless: Forgets to take a backup, snapshots, has multiple working directories of code, leaves system out, prints in production code, etc. Again, this is a newbie tendency and gets better with more professional exposure.

10) The lazy pseudo-hacker: They pride themselves at being able to trick the system into working. They find magical solutions to seemingly complex problems. My experience says that 9 out of 10 times, it's just a facade. The hack is bad and will crash sooner or later and will cost much more than having to deal with it, with extra time right now.

EDIT: Please drop in comments. Maybe we could start a new follow-up question as to how a managers/peers/colleagues could handle these cases because almost all of them can be helped to become better. A design pattern of sorts for fixing programmer smells. :-)



軟體吞噬世界,開發者這個職業炙手可熱的程度前所未有,而且只會愈來愈熱門。許多人意識到這股潮流,加入寫程式的行列。不過別看矽谷工程師坐擁高 薪,這可是個強者如雲、充滿挑戰的環境。也因如此,開發者品質的優劣判斷總是在網路上引發熱烈討論。Quora 上就有這麼一道長壽的問題「糟糕的軟體工程師有什麼特徵」,亞馬遜軟體開發工程師 Nachiket Naik 的回答頗為中肯,獲得幾千名網友贊同。邁向頂尖開發者的道路上,你該避免成為下列十種討厭鬼。

1. 只會複製貼上的機器人

程式設計問答網站 Stack Overflow 擁有非常豐碩的資源,很多人寫程式碰壁了就會上去找解答,Stack Overflow 本身並沒有錯,它是工程師的得力助手。但是如果只是複製貼上,改個參數,不去了解前因後果,不去弄懂為何這樣的解法到底是不是真的適用於現在面臨的問題, 那當然很難進步。有不少工程師寧可相信他們在網路論壇看到的說法,而不願意費心思考眼前的程式碼或系統。

2. 懶得測試

「我不幹測試這種事,那是測試工程師的責任。」即使在敏捷開發方法如此盛行的時代,這種態度依舊層出不窮。工程師不願測試的惰性還是很普遍。有可能是他們討厭設定測試環境,也有可能是缺乏測試的連貫性知識。當然,也或許是,測試工程師在開發者社群中總存在著不能說的污名。

3. 不寫文件

有些人覺得程式文件(code documentation)應該如詩一般簡潔美麗,他們沒能力做到這樣,就乾脆不做了。可我認為這樣的心態是軟體開發的頭號公敵。傑出的軟體,不需要有 幾百萬個酷炫的功能,傑出的軟體,應該是要提供幾個讓人「離不開」不斷使用的功能,而且這幾個功能背後有幾千個人閱讀、更新、修正。輕視技術溝通、文件精 確度、忽略細節的開發者,肯定是公司獲得成功最大的絆腳石。

4. 程式寫得很醜

我的程式能跑,但⋯⋯
  • 有些變數被命名為 x、flag、str、arr⋯⋯
  • Most of what I write is in one giant method.
  • 忘了縮排
  • 缺乏連貫的程式慣例或風格
  • 把全域變數噴灑得到處都是
對作者來說,這簡直是最惱人的事。雖然某段程式碼不見得差,甚至有可能是寫得最好的部分。只是,如果出現上述情況,就像一條鑽石項鍊被埋葬在鐵達尼號的殘骸中,沒人找得到它,也沒人想清理它、佩戴它、使用它。

5. 只能衝刺而無法跑千里

他寫程式、他部署、他繼續前進,絲毫沒有想要學著解決問題的意願,只要給這傢伙一段程式碼,他就會沒日沒夜奮戰,隔天就交出成果,你會得到一個修復 好、能執行的軟體,除此之外別無所有。有時候,選擇開發者的時候你得有些私心,找個不但會在大限之前完成任務,而且也有旺盛的求知慾的人。

6. 一天到晚怨天尤人

「這不是我幹的」、「這不是我的錯」、「這跟我修復的部分無關,一定是有其他人搞砸了」、「這東西真的很煩!(無限迴圈)」、「我不知道怎麼修復這邊,找個會的人來啦」⋯⋯
那個犯錯的人可能早就修正向前走了,你還在大肆抱怨什麼勁呢?

7. 這個世界唯我獨尊

「不照我的方法做就拉倒」,是這群人的座右銘。在他們心中,這是一場他的「點子」與你的「點子」之間、他的解決方案與你的解決方案之間的競爭,不為 整個專案著想。他們會來來回回仔細你植入的程式碼,即使他們運作正常、經過測試、看來完美無缺,仍讓他們覺得芒刺在背。這類傢伙是阻礙生產力的大麻煩,在 壓力來襲時,他們也會是最先落荒而逃的人,就算經驗再怎麼豐富、技術再怎麼厲害,也別輕易嘗試找這些人加入團隊。

8. 不願踏出舒適圈

寫 Java 的 A 開發者一聽到他得寫一段 Python script 就愣住了。B 開發者一聽到設定檔裡某個部分必須改正就慌了。C 開發者一聽到他得在資料庫裡輸入東西就畏縮了。這些人傾向趨吉避凶,不願離開舒適圈。他們有很奇異的迷信,不想接觸系統的某些地方。這個現象尤其容易出現 在菜鳥開發者身上,出色的開發者或快或慢,都會渴望跳出舒適圈,探索陌生的事物。

9. 粗枝大葉

忘掉留存備份、快照存檔、一堆未歸檔的程式目錄⋯⋯這些都是菜鳥容易出的狀況,隨著你愈來愈朝專業者邁進,這些漫不經心的狀況都應該避免。

10. 偽裝成駭客的麻煩精

這些人能夠耍些小技倆,「騙過」系統使之運作,沾沾自喜。面對複雜的問題,他們彷彿變個魔術就能解決,但就作者的經驗,10 次有 9 次都只是表面功夫,實則漏洞百出,而且遲早都會當掉,導致後來還要花更多成本處理。


2016年4月26日 星期二

How to Install Bluestacks Without Graphics Card

Reference:


How to Install Bluestacks without Graphics Card – Bluestacks App Player is a great innovation in the Software field that has impressed millions of worldwide audience and to be honest it really deserves it.It has gained immense popularity and appreciation since its release and most surprisingly this App Player is still in beta testing phase and we can’t even imagine right now how may users will be using Bluestacks App Player in future after its final release and this would certainly be a golden moment for all the developers of Bluestacks as well its users but still there are some users who are not aware about Bluestacks Till date so if you are one of them here below is a short brief description about Bluestacks App Player that will help you get more familiar with Bluestacks.
Also Read :
Bluestacks in simple words is an Android Emulator which basically creates a virtual environment for all the Android Apps and games thereby enabling them to run on Windows PC or MaxOSX thinking the Bluestacks App Player to be an Android Device.BlueStacks App Player lets you run your favorite mobile apps fast and full screen in your browser and on PC or Mac.The Best part of using bluestacks is that it integrates seamlessly with your Windows and all the android apps that you will install in your Bluestacks App Player without facing any issues at all.How to Install Bluestacks without Graphics Card
Though no doubt there are few other similar android emulators are also in the market but trust me Bluestacks App Player is thus far the best as far as your system fully supports it and available absolutely free of cost for lifetime.
Also Read :
I have followed Bluestacks since its release and during this period till now I have received hundreds of mails in regards to the two top most common issues faced by while Using Bluestacks App out of which first one is Requirement of Graphics Card for Installing Bluestacks and second one is requirement of 2GB Memory at least which is not possible to have in every system. I have already discussed some issues related to bluestacks with their proper solution like Graphic Card Error 2500, Runtime download data error etc.Just follow the given guide to learn How to Install Bluestacks without graphics card.
Also Read :

How to Install Bluestacks Without Graphics Card – Steps to Proceed

With regards to Graphics Card Issue while using bluestacks you may face two types of error either the Error during Installation period like BlueStacks currently doesn’t recognize your graphics card. It is possible your Graphics Drivers may need to be updated. Please update them and try installing again (If installed from Offline Bluestacks Installer) or Error 25000 BlueStacks currently doesn’t recognize your graphics card. It is possible your Graphics Drivers may need to be updated. Please update them and try installing again (If Installed from Bluestacks Split Installer) but don’t worry both of them means the same.
  • After Installing Orca just go to the Bluestacks Offline Installer.msi file and Perform a Right Click on the Installer -> Select Edit with Orca
Install Bluestacks without Graphics Card - 1
  • Go to LaunchCondition > Select “Installed OR PhysicalMemory >=1024” condition > Press Delete > Select OK.
Install Bluestacks without Graphics Card - 2
Note – This will allow you to Install Bluestacks in systems with 1GB of RAM thereby passing the 2GB RAM verification test.
  • Go to InstallExecuteSequence > Click on “CheckMsiSignature> Hit Delete > Click OK
Install Bluestacks without Graphics Card - 3
  • Go to Property > Double click on the TRUE value of GLMODE > Change its value to FALSE > Hit Enter
Install Bluestacks without Graphics Card - 4
  • Click on the Save button icon and that’s it you are all done.
Install Bluestacks without Graphics Card - 5
  • Start Installing Bluestacks again from the saved Bluestacks offline installer and you will no longer face the same error.

2016年3月10日 星期四

top command in batch mode

When issue `top -b -n 1`, console showed the following message:
'dumb': unknown terminal type.
Check if the system is missing "/lib/terminfo/d/dumb" and copy it from another system.
If the error is still occurred, try `ln -s /lib/terminfo/d/dumb /usr/share/terminfo/d/dumb` and see if it helps.

The hexdump result of "dumb" (308 bytes) from Ubuntu system:

000000001A 01 18 00 02 00 01 00 82 00 08 00 64 75 6D 62|............dumb|
000000107C 38 30 2D 63 6F 6C 75 6D 6E 20 64 75 6D 62 20||80-column dumb |
0000002074 74 79 00 00 01 50 00 FF FF 00 00 02 00 FF FF|tty...P.........|
00000030FF FF FF FF FF FF FF FF FF FF FF FF FF FF 04 00|................|
00000040FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF|................|
*
00000120FF FF FF FF FF FF FF FF FF FF 06 00 07 00 0D 00|................|
000001300A 00 0A 00 |....|
00000134

2015年12月1日 星期二

Default cluster size for NTFS, FAT, and exFAT

Default cluster size for NTFS, FAT, and exFAT

Summary

All file systems that are used by Windows organize your hard disk based on cluster size (also known as allocation unit size). Cluster size represents the smallest amount of disk space that can be used to hold a file. When file sizes do not come out to an even multiple of the cluster size, additional space must be used to hold the file (up to the next multiple of the cluster size). On the typical hard disk partition, the average amount of space that is lost in this manner can be calculated by using the equation (cluster size)/2 * (number of files).

If no cluster size is specified when you format a partition, defaults are selected based on the size of the partition. These defaults are selected to reduce the space that is lost and to reduce the fragmentation that occurs on the partition. 
More information
A hard disk partition (also known as a volume) can be formatted to NTFS, FAT, or exFAT. The default values are used by Windows when one of the following methods is used to format the partition:
  • Using the FORMAT command from the command line without specifying a cluster size.
  • Formatting a volume from Windows Explorer when the Allocation Unit box in the Format dialog box lists Default Allocation Size.

By default, the maximum cluster size for NTFS under Windows NT 4.0 and later versions of Windows is 4 kilobytes (KB). This is because NTFS file compression is not possible on drives that have a larger cluster size. The format command won't use clusters larger than 4 KB unless the user specifically overrides the default settings. You can do this by using the /A: switch together with the Format command or by specifying a larger cluster size in the Format dialog box in Windows Explorer.

When you use the Convert.exe utility to convert a FAT partition to NTFS, Windows always uses the original FAT cluster size as the NTFS cluster size for cluster sizes up to 4 KB. If the FAT cluster size is greater than 4 KB, then the clusters are converted down to 4 KB in NTFS. This is because the FAT structures are aligned on cluster boundaries. Therefore, any larger cluster size would not allow for the conversion to function. Note also when formatting a partition under Windows NT 3.5, 3.51, and 4.0 Setup, the partition is first formatted to FAT and then converted to NTFS, so the cluster size will also always be as described earlier when a partition is formatted in Setup.

Default cluster sizes for NTFS

The following table describes the default cluster sizes for NTFS.
Volume size Windows NT 3.51Windows NT 4.0Windows 7, Windows Server 2008 R2, Windows Server 2008, Windows Vista, Windows Server 2003, Windows XP, Windows 2000
7 MB–512 MB 512 bytes4 KB4 KB
512 MB–1 GB 1 KB4 KB4 KB
1 GB–2 GB 2 KB4 KB4 KB
2 GB–2 TB 4 KB4 KB4 KB
2 TB–16 TB Not Supported*Not Supported*4 KB
16TB–32 TB Not Supported*Not Supported*8 KB
32TB–64 TBNot Supported*Not Supported*16 KB
64TB–128 TBNot Supported*Not Supported*32 KB
128TB–256 TBNot Supported*Not Supported*64 KB
> 256 TBNot SupportedNot SupportedNot Supported

Note The asterisk (*) means that it is not supported because of the limitations of the master boot record (MBR).

Default cluster sizes for FAT16

The following table describes the default cluster sizes for FAT16.
Volume size Windows NT 3.51Windows NT 4.0Windows 7, Windows Server 2008 R2, Windows Server 2008, Windows Vista, Windows Server 2003, Windows XP, Windows 2000 
7 MB–8 MB Not supported Not supportedNot supported
8 MB–32 MB 512 bytes512 bytes512 bytes
32 MB–64 MB 1 KB 1 KB 1 KB
64 MB–128 MB 2 KB2 KB2 KB
128 MB–256 MB4 KB4 KB4 KB
256 MB–512 MB8 KB8 KB8 KB
512 MB–1 GB 16 KB 16 KB 16 KB
1 GB–2 GB 32 KB32 KB32 KB
2 GB–4 GB 64 KB64 KB64 KB
4 GB–8 GB Not supported 128 KB*Not supported
8 GB–16 GB Not supported 256 KB*Not supported
> 16 GBNot supported Not supportedNot supported
Note The asterisk (*) means that it is available only on media with a sector size greater than 512 bytes.

Default cluster sizes for FAT32

The following table describes the default cluster sizes for FAT32.
Volume sizeWindows NT 3.51Windows NT 4.0Windows 7, Windows Server 2008 R2, Windows Server 2008, Windows Vista, Windows Server 2003, Windows XP, Windows 2000 
7 MB–16MB Not supported Not supportedNot supported
16 MB–32 MB 512 bytes512 bytesNot supported
32 MB–64 MB 512 bytes512 bytes512 bytes
64 MB–128 MB 1 KB1 KB1 KB
128 MB–256 MB2 KB2 KB2 KB
256 MB–8GB4 KB4 KB4 KB
8GB–16GB 8 KB8 KB8 KB
16GB–32GB 16 KB16 KB16 KB
32GB–2TB 32 KBNot supported Not supported
> 2TBNot supported Not supportedNot supported

Default cluster sizes for exFAT

The following table describes the default cluster sizes for exFAT.
Volume size Windows 7, Windows Server 2008 R2, Windows Server 2008, Windows Vista, Windows Server 2003, Windows XP
7 MB–256 MB 4 KB
256 MB–32 GB 32 KB
32 GB–256 TB 128 KB
> 256 TB Not supported

Reference:

https://support.microsoft.com/en-gb/kb/140365

2015年11月26日 星期四

C / C++ Macro Tips

Stringification

Sometimes you may want to convert a macro argument into a string constant. Parameters are not replaced inside string constants, but you can use the ‘#’ preprocessing operator instead. When a macro parameter is used with a leading ‘#’, the preprocessor replaces it with the literal text of the actual argument, converted to a string constant. Unlike normal parameter replacement, the argument is not macro-expanded first. This is called stringification.
There is no way to combine an argument with surrounding text and stringify it all together. Instead, you can write a series of adjacent string constants and stringified arguments. The preprocessor will replace the stringified arguments with string constants. The C compiler will then combine all the adjacent string constants into one long string.
Here is an example of a macro definition that uses stringification:
     #define WARN_IF(EXP) \
     do { if (EXP) \
             fprintf (stderr, "Warning: " #EXP "\n"); } \
     while (0)
     WARN_IF (x == 0);
          ==> do { if (x == 0)
                fprintf (stderr, "Warning: " "x == 0" "\n"); } while (0);
The argument for EXP is substituted once, as-is, into the if statement, and once, stringified, into the argument to fprintf. If x were a macro, it would be expanded in the if statement, but not in the string.
The do and while (0) are a kludge to make it possible to write WARN_IF (arg);, which the resemblance of WARN_IF to a function would make C programmers want to do; see Swallowing the Semicolon.
Stringification in C involves more than putting double-quote characters around the fragment. The preprocessor backslash-escapes the quotes surrounding embedded string constants, and all backslashes within string and character constants, in order to get a valid C string constant with the proper contents. Thus, stringifying p = "foo\n"; results in "p = \"foo\\n\";". However, backslashes that are not inside string or character constants are not duplicated: ‘\n’ by itself stringifies to "\n".
All leading and trailing whitespace in text being stringified is ignored. Any sequence of whitespace in the middle of the text is converted to a single space in the stringified result. Comments are replaced by whitespace long before stringification happens, so they never appear in stringified text.
There is no way to convert a macro argument into a character constant.
If you want to stringify the result of expansion of a macro argument, you have to use two levels of macros.
     #define xstr(s) str(s)
     #define str(s) #s
     #define foo 4
     str (foo)
          ==> "foo"
     xstr (foo)
          ==> xstr (4)
          ==> str (4)
          ==> "4"
s is stringified when it is used in str, so it is not macro-expanded first. But s is an ordinary argument to xstr, so it is completely macro-expanded before xstr itself is expanded (see Argument Prescan). Therefore, by the time str gets to its argument, it has already been macro-expanded.

Concatenation

It is often useful to merge two tokens into one while expanding macros. This is called token pasting or token concatenation. The ‘##’ preprocessing operator performs token pasting. When a macro is expanded, the two tokens on either side of each ‘##’ operator are combined into a single token, which then replaces the ‘##’ and the two original tokens in the macro expansion. Usually both will be identifiers, or one will be an identifier and the other a preprocessing number. When pasted, they make a longer identifier. This isn't the only valid case. It is also possible to concatenate two numbers (or a number and a name, such as 1.5 and e3) into a number. Also, multi-character operators such as += can be formed by token pasting.
However, two tokens that don't together form a valid token cannot be pasted together. For example, you cannot concatenate x with + in either order. If you try, the preprocessor issues a warning and emits the two tokens. Whether it puts white space between the tokens is undefined. It is common to find unnecessary uses of ‘##’ in complex macros. If you get this warning, it is likely that you can simply remove the ‘##’.
Both the tokens combined by ‘##’ could come from the macro body, but you could just as well write them as one token in the first place. Token pasting is most useful when one or both of the tokens comes from a macro argument. If either of the tokens next to an ‘##’ is a parameter name, it is replaced by its actual argument before ‘##’ executes. As with stringification, the actual argument is not macro-expanded first. If the argument is empty, that ‘##’ has no effect.
Keep in mind that the C preprocessor converts comments to whitespace before macros are even considered. Therefore, you cannot create a comment by concatenating ‘/’ and ‘*’. You can put as much whitespace between ‘##’ and its operands as you like, including comments, and you can put comments in arguments that will be concatenated. However, it is an error if ‘##’ appears at either end of a macro body.
Consider a C program that interprets named commands. There probably needs to be a table of commands, perhaps an array of structures declared as follows:
     struct command
     {
       char *name;
       void (*function) (void);
     };
     
     struct command commands[] =
     {
       { "quit", quit_command },
       { "help", help_command },
       ...
     };
It would be cleaner not to have to give each command name twice, once in the string constant and once in the function name. A macro which takes the name of a command as an argument can make this unnecessary. The string constant can be created with stringification, and the function name by concatenating the argument with ‘_command’. Here is how it is done:
     #define COMMAND(NAME)  { #NAME, NAME ## _command }
     
     struct command commands[] =
     {
       COMMAND (quit),
       COMMAND (help),
       ...
     };

Variadic Macros

A macro can be declared to accept a variable number of arguments much as a function can. The syntax for defining the macro is similar to that of a function. Here is an example:
#define eprintf(...) fprintf (stderr, __VA_ARGS__) This kind of macro is called variadic. When the macro is invoked, all the tokens in its argument list after the last named argument (this macro has none), including any commas, become the variable argument. This sequence of tokens replaces the identifier __VA_ARGS__ in the macro body wherever it appears. Thus, we have this expansion:
eprintf ("%s:%d: ", input_file, lineno) ==> fprintf (stderr, "%s:%d: ", input_file, lineno) The variable argument is completely macro-expanded before it is inserted into the macro expansion, just like an ordinary argument. You may use the ‘#’ and ‘##’ operators to stringify the variable argument or to paste its leading or trailing token with another token. (But see below for an important special case for ‘##’.)
If your macro is complicated, you may want a more descriptive name for the variable argument than __VA_ARGS__. CPP permits this, as an extension. You may write an argument name immediately before the ‘...’; that name is used for the variable argument. The eprintf macro above could be written
#define eprintf(args...) fprintf (stderr, args)
using this extension. You cannot use __VA_ARGS__ and this extension in the same macro.
You can have named arguments as well as variable arguments in a variadic macro. We could define eprintf like this, instead:
#define eprintf(format, ...) fprintf (stderr, format, __VA_ARGS__)
This formulation looks more descriptive, but unfortunately it is less flexible: you must now supply at least one argument after the format string. In standard C, you cannot omit the comma separating the named argument from the variable arguments. Furthermore, if you leave the variable argument empty, you will get a syntax error, because there will be an extra comma after the format string.
eprintf("success!\n", ); ==> fprintf(stderr, "success!\n", ); GNU CPP has a pair of extensions which deal with this problem. First, you are allowed to leave the variable argument out entirely:
eprintf ("success!\n") ==> fprintf(stderr, "success!\n", );
Second, the ‘##’ token paste operator has a special meaning when placed between a comma and a variable argument. If you write
#define eprintf(format, ...) fprintf (stderr, format, ##__VA_ARGS__)
and the variable argument is left out when the eprintf macro is used, then the comma before the ‘##’ will be deleted. This does not happen if you pass an empty argument, nor does it happen if the token preceding ‘##’ is anything other than a comma.
eprintf ("success!\n") ==> fprintf(stderr, "success!\n");
The above explanation is ambiguous about the case where the only macro parameter is a variable arguments parameter, as it is meaningless to try to distinguish whether no argument at all is an empty argument or a missing argument. In this case the C99 standard is clear that the comma must remain, however the existing GCC extension used to swallow the comma. So CPP retains the comma when conforming to a specific C standard, and drops it otherwise.
C99 mandates that the only place the identifier __VA_ARGS__ can appear is in the replacement list of a variadic macro. It may not be used as a macro name, macro argument name, or within a different type of macro. It may also be forbidden in open text; the standard is ambiguous. We recommend you avoid using it except for its defined purpose.
Variadic macros are a new feature in C99. GNU CPP has supported them for a long time, but only with a named variable argument (‘args...’, not ‘...’ and __VA_ARGS__). If you are concerned with portability to previous versions of GCC, you should use only named variable arguments. On the other hand, if you are concerned with portability to other conforming implementations of C99, you should use only __VA_ARGS__.
Previous versions of CPP implemented the comma-deletion extension much more generally. We have restricted it in this release to minimize the differences from C99. To get the same effect with both this and previous versions of GCC, the token preceding the special ‘##’ must be a comma, and there must be white space between that comma and whatever comes immediately before it:
#define eprintf(format, args...) fprintf (stderr, format , ##args)
See Differences from previous versions, for the gory details.


About Double Parentheses:
If you see something like "SOME_MACRO (("%s, %d, %u", arg1, arg2, arg3));", you could probably define the "SOME_MACRO" as the following to use on it functions like printf():
#define SOME_MACRO(x) \
    printf x;
Otherwise, use the "Variadic Macros" described above.

Reference:

https://gcc.gnu.org/onlinedocs/cpp/Macros.html#Macros
http://www.tutorialspoint.com/cprogramming/c_preprocessors.htm
http://stackoverflow.com/questions/5812877/why-one-needs-two-brackets-to-use-macros-in-c-c

2015年11月10日 星期二

Declaring Attributes of Functions

Declaring Attributes of Functions


In GNU C, you declare certain things about functions called in your program which help the compiler optimize function calls and check your code more carefully.
The keyword __attribute__ allows you to specify special attributes when making a declaration. This keyword is followed by an attribute specification inside double parentheses. The following attributes are currently defined for functions on all targets: noreturn, noinline, always_inline, pure, const, nothrow, format, format_arg, no_instrument_function, section, constructor, destructor, used, unused, deprecated, weak, malloc, alias, and nonnull. Several other attributes are defined for functions on particular target systems. Other attributes, including section are supported for variables declarations (see Variable Attributes) and for types (see Type Attributes).
You may also specify attributes with __ preceding and following each keyword. This allows you to use them in header files without being concerned about a possible macro of the same name. For example, you may use __noreturn__ instead of noreturn.
See Attribute Syntax, for details of the exact syntax for using attributes.
noreturn
A few standard library functions, such as abort and exit, cannot return. GCC knows this automatically. Some programs define their own functions that never return. You can declare them noreturn to tell the compiler this fact. For example,
          void fatal () __attribute__ ((noreturn));
          
          void
          fatal (/* ... */)
          {
            /* ... */ /* Print error message. */ /* ... */
            exit (1);
          }
          
The noreturn keyword tells the compiler to assume that fatal cannot return. It can then optimize without regard to what would happen if fatal ever did return. This makes slightly better code. More importantly, it helps avoid spurious warnings of uninitialized variables.
Do not assume that registers saved by the calling function are restored before calling the noreturn function.
It does not make sense for a noreturn function to have a return type other than void.
The attribute noreturn is not implemented in GCC versions earlier than 2.5. An alternative way to declare that a function does not return, which works in the current version and in some older versions, is as follows:
          typedef void voidfn ();
          
          volatile voidfn fatal;
          
noinline
This function attribute prevents a function from being considered for inlining.
always_inline
Generally, functions are not inlined unless optimization is specified. For functions declared inline, this attribute inlines the function even if no optimization level was specified.
pure
Many functions have no effects except the return value and their return value depends only on the parameters and/or global variables. Such a function can be subject to common subexpression elimination and loop optimization just as an arithmetic operator would be. These functions should be declared with the attribute pure. For example,
          int square (int) __attribute__ ((pure));
          
says that the hypothetical function square is safe to call fewer times than the program says.
Some of common examples of pure functions are strlen or memcmp. Interesting non-pure functions are functions with infinite loops or those depending on volatile memory or other system resource, that may change between two consecutive calls (such as feof in a multithreading environment).
The attribute pure is not implemented in GCC versions earlier than 2.96.
const
Many functions do not examine any values except their arguments, and have no effects except the return value. Basically this is just slightly more strict class than the pure attribute above, since function is not allowed to read global memory. Note that a function that has pointer arguments and examines the data pointed to must not be declared const. Likewise, a function that calls a non-const function usually must not be const. It does not make sense for a const function to return void.
The attribute const is not implemented in GCC versions earlier than 2.5. An alternative way to declare that a function has no side effects, which works in the current version and in some older versions, is as follows:
          typedef int intfn ();
          
          extern const intfn square;
          
This approach does not work in GNU C++ from 2.6.0 on, since the language specifies that the const must be attached to the return value.
nothrow
The nothrow attribute is used to inform the compiler that a function cannot throw an exception. For example, most functions in the standard C library can be guaranteed not to throw an exception with the notable exceptions of qsort and bsearch that take function pointer arguments. The nothrow attribute is not implemented in GCC versions earlier than 3.2.
format (archetype, string-index, first-to-check)
The format attribute specifies that a function takes printf, scanf, strftime or strfmon style arguments which should be type-checked against a format string. For example, the declaration:
          extern int
          my_printf (void *my_object, const char *my_format, ...)
                __attribute__ ((format (printf, 2, 3)));
          
causes the compiler to check the arguments in calls to my_printf for consistency with the printf style format string argument my_format.
The parameter archetype determines how the format string is interpreted, and should be printf, scanf, strftime or strfmon. (You can also use __printf__, __scanf__, __strftime__ or __strfmon__.) The parameter string-index specifies which argument is the format string argument (starting from 1), while first-to-check is the number of the first argument to check against the format string. For functions where the arguments are not available to be checked (such as vprintf), specify the third parameter as zero. In this case the compiler only checks the format string for consistency. For strftime formats, the third parameter is required to be zero.
In the example above, the format string (my_format) is the second argument of the function my_print, and the arguments to check start with the third argument, so the correct parameters for the format attribute are 2 and 3.
The format attribute allows you to identify your own functions which take format strings as arguments, so that GCC can check the calls to these functions for errors. The compiler always (unless -ffreestanding is used) checks formats for the standard library functions printf, fprintf, sprintf, scanf, fscanf, sscanf, strftime, vprintf, vfprintf and vsprintf whenever such warnings are requested (using -Wformat), so there is no need to modify the header file stdio.h. In C99 mode, the functions snprintf, vsnprintf, vscanf, vfscanf and vsscanf are also checked. Except in strictly conforming C standard modes, the X/Open function strfmon is also checked as are printf_unlocked and fprintf_unlocked. See Options Controlling C Dialect.
format_arg (string-index)
The format_arg attribute specifies that a function takes a format string for a printf, scanf, strftime or strfmon style function and modifies it (for example, to translate it into another language), so the result can be passed to a printf, scanf, strftime or strfmon style function (with the remaining arguments to the format function the same as they would have been for the unmodified string). For example, the declaration:
          extern char *
          my_dgettext (char *my_domain, const char *my_format)
                __attribute__ ((format_arg (2)));
          
causes the compiler to check the arguments in calls to a printf, scanf, strftime or strfmon type function, whose format string argument is a call to the my_dgettext function, for consistency with the format string argument my_format. If the format_arg attribute had not been specified, all the compiler could tell in such calls to format functions would be that the format string argument is not constant; this would generate a warning when -Wformat-nonliteral is used, but the calls could not be checked without the attribute.
The parameter string-index specifies which argument is the format string argument (starting from 1).
The format-arg attribute allows you to identify your own functions which modify format strings, so that GCC can check the calls to printf, scanf, strftime or strfmon type function whose operands are a call to one of your own function. The compiler always treats gettext, dgettext, and dcgettext in this manner except when strict ISO C support is requested by -ansi or an appropriate -std option, or -ffreestanding is used. See Options Controlling C Dialect.
nonnull (arg-index, ...)
The nonnull attribute specifies that some function parameters should be non-null pointers. For instance, the declaration:
          extern void *
          my_memcpy (void *dest, const void *src, size_t len)
           __attribute__((nonnull (1, 2)));
          
causes the compiler to check that, in calls to my_memcpy, arguments dest and src are non-null. If the compiler determines that a null pointer is passed in an argument slot marked as non-null, and the -Wnonnull option is enabled, a warning is issued. The compiler may also choose to make optimizations based on the knowledge that certain function arguments will not be null.
If no argument index list is given to the nonnull attribute, all pointer arguments are marked as non-null. To illustrate, the following declaration is equivalent to the previous example:
          extern void *
          my_memcpy (void *dest, const void *src, size_t len)
           __attribute__((nonnull));
          
no_instrument_function
If -finstrument-functions is given, profiling function calls will be generated at entry and exit of most user-compiled functions. Functions with this attribute will not be so instrumented.
section ("section-name")
Normally, the compiler places the code it generates in the text section. Sometimes, however, you need additional sections, or you need certain particular functions to appear in special sections. The section attribute specifies that a function lives in a particular section. For example, the declaration:
          extern void foobar (void) __attribute__ ((section ("bar")));
          
puts the function foobar in the bar section.
Some file formats do not support arbitrary sections so the section attribute is not available on all platforms. If you need to map the entire contents of a module to a particular section, consider using the facilities of the linker instead.
constructor

destructor
The constructor attribute causes the function to be called automatically before execution enters main (). Similarly, the destructor attribute causes the function to be called automatically after main () has completed or exit () has been called. Functions with these attributes are useful for initializing data that will be used implicitly during the execution of the program. These attributes are not currently implemented for Objective-C.
unused
This attribute, attached to a function, means that the function is meant to be possibly unused. GCC will not produce a warning for this function. GNU C++ does not currently support this attribute as definitions without parameters are valid in C++.
used
This attribute, attached to a function, means that code must be emitted for the function even if it appears that the function is not referenced. This is useful, for example, when the function is referenced only in inline assembly.
deprecated
The deprecated attribute results in a warning if the function is used anywhere in the source file. This is useful when identifying functions that are expected to be removed in a future version of a program. The warning also includes the location of the declaration of the deprecated function, to enable users to easily find further information about why the function is deprecated, or what they should do instead. Note that the warnings only occurs for uses:
          int old_fn () __attribute__ ((deprecated));
          int old_fn ();
          int (*fn_ptr)() = old_fn;
          
results in a warning on line 3 but not line 2.
The deprecated attribute can also be used for variables and types (see Variable Attributes, see Type Attributes.)
weak
The weak attribute causes the declaration to be emitted as a weak symbol rather than a global. This is primarily useful in defining library functions which can be overridden in user code, though it can also be used with non-function declarations. Weak symbols are supported for ELF targets, and also for a.out targets when using the GNU assembler and linker.
malloc
The malloc attribute is used to tell the compiler that a function may be treated as if it were the malloc function. The compiler assumes that calls to malloc result in a pointers that cannot alias anything. This will often improve optimization.
alias ("target")
The alias attribute causes the declaration to be emitted as an alias for another symbol, which must be specified. For instance,
          void __f () { /* Do something. */; }
          void f () __attribute__ ((weak, alias ("__f")));
          
declares f to be a weak alias for __f. In C++, the mangled name for the target must be used.
Not all target machines support this attribute.
visibility ("visibility_type")
The visibility attribute on ELF targets causes the declaration to be emitted with default, hidden, protected or internal visibility.
          void __attribute__ ((visibility ("protected")))
          f () { /* Do something. */; }
          int i __attribute__ ((visibility ("hidden")));
          
See the ELF gABI for complete details, but the short story is
default
Default visibility is the normal case for ELF. This value is available for the visibility attribute to override other options that may change the assumed visibility of symbols.
hidden
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.
protected
Protected visibility indicates that the symbol will be placed in the dynamic symbol table, but that references within the defining module will bind to the local symbol. That is, the symbol cannot be overridden by another module.
internal
Internal visibility is like hidden visibility, but with additional processor specific semantics. Unless otherwise specified by the psABI, gcc defines internal visibility to mean that the function is never called from another module. Note that hidden symbols, while then cannot be referenced directly by other modules, can be referenced indirectly via function pointers. By indicating that a symbol cannot be called from outside the module, gcc may for instance omit the load of a PIC register since it is known that the calling function loaded the correct value.
Not all ELF targets support this attribute.
tls_model ("tls_model")
The tls_model attribute sets thread-local storage model (see Thread-Local) of a particular __thread variable, overriding -ftls-model= command line switch on a per-variable basis. The tls_model argument should be one of global-dynamic, local-dynamic, initial-exec or local-exec.
regparm (number)
On the Intel 386, the regparm attribute causes the compiler to pass up to number integer arguments in registers EAX, EDX, and ECX instead of on the stack. Functions that take a variable number of arguments will continue to be passed all of their arguments on the stack.
stdcall
On the Intel 386, the stdcall attribute causes the compiler to assume that the called function will pop off the stack space used to pass arguments, unless it takes a variable number of arguments. The PowerPC compiler for Windows NT currently ignores the stdcall attribute.
cdecl
On the Intel 386, the cdecl attribute causes the compiler to assume that the calling function will pop off the stack space used to pass arguments. This is useful to override the effects of the -mrtd switch. The PowerPC compiler for Windows NT currently ignores the cdecl attribute.
longcall/shortcall
On the RS/6000 and PowerPC, the longcall attribute causes the compiler to always call this function via a pointer, just as it would if the -mlongcall option had been specified. The shortcall attribute causes the compiler not to do this. These attributes override both the -mlongcall switch and the #pragma longcall setting. See RS/6000 and PowerPC Options, for more information on when long calls are and are not necessary.
long_call/short_call
This attribute allows to specify how to call a particular function on ARM. Both attributes override the -mlong-calls (see ARM Options) command line switch and #pragma long_calls settings. The long_call attribute causes the compiler to always call the function by first loading its address into a register and then using the contents of that register. The short_call attribute always places the offset to the function from the call site into the BL instruction directly.
dllimport
On the PowerPC running Windows NT, the dllimport attribute causes the compiler to call the function via a global pointer to the function pointer that is set up by the Windows NT dll library. The pointer name is formed by combining __imp_ and the function name.
dllexport
On the PowerPC running Windows NT, the dllexport attribute causes the compiler to provide a global pointer to the function pointer, so that it can be called with the dllimport attribute. The pointer name is formed by combining __imp_ and the function name.
exception (except-func [, except-arg])
On the PowerPC running Windows NT, the exception attribute causes the compiler to modify the structured exception table entry it emits for the declared function. The string or identifier except-func is placed in the third entry of the structured exception table. It represents a function, which is called by the exception handling mechanism if an exception occurs. If it was specified, the string or identifier except-arg is placed in the fourth entry of the structured exception table.
function_vector
Use this attribute on the H8/300 and H8/300H to indicate that the specified function should be called through the function vector. Calling a function through the function vector will reduce code size, however; the function vector has a limited size (maximum 128 entries on the H8/300 and 64 entries on the H8/300H) and shares space with the interrupt vector. You must use GAS and GLD from GNU binutils version 2.7 or later for this attribute to work correctly.
interrupt
Use this attribute on the ARM, AVR, M32R/D and Xstormy16 ports to indicate that the specified function is an interrupt handler. The compiler will generate function entry and exit sequences suitable for use in an interrupt handler when this attribute is present. Note, interrupt handlers for the H8/300, H8/300H and SH processors can be specified via the interrupt_handler attribute.
Note, on the AVR interrupts will be enabled inside the function.
Note, for the ARM you can specify the kind of interrupt to be handled by adding an optional parameter to the interrupt attribute like this:
          void f () __attribute__ ((interrupt ("IRQ")));
          
Permissible values for this parameter are: IRQ, FIQ, SWI, ABORT and UNDEF.
interrupt_handler
Use this attribute on the H8/300, H8/300H and SH to indicate that the specified function is an interrupt handler. The compiler will generate function entry and exit sequences suitable for use in an interrupt handler when this attribute is present.
sp_switch
Use this attribute on the SH to indicate an interrupt_handler function should switch to an alternate stack. It expects a string argument that names a global variable holding the address of the alternate stack.
          void *alt_stack;
          void f () __attribute__ ((interrupt_handler,
                                    sp_switch ("alt_stack")));
          
trap_exit
Use this attribute on the SH for an interrupt_handle to return using trapa instead of rte. This attribute expects an integer argument specifying the trap number to be used.
eightbit_data
Use this attribute on the H8/300 and H8/300H to indicate that the specified variable should be placed into the eight bit data section. The compiler will generate more efficient code for certain operations on data in the eight bit data area. Note the eight bit data area is limited to 256 bytes of data. You must use GAS and GLD from GNU binutils version 2.7 or later for this attribute to work correctly.
tiny_data
Use this attribute on the H8/300H to indicate that the specified variable should be placed into the tiny data section. The compiler will generate more efficient code for loads and stores on data in the tiny data section. Note the tiny data area is limited to slightly under 32kbytes of data.
signal
Use this attribute on the AVR to indicate that the specified function is an signal handler. The compiler will generate function entry and exit sequences suitable for use in an signal handler when this attribute is present. Interrupts will be disabled inside function.
naked
Use this attribute on the ARM, AVR and IP2K ports to indicate that the specified function do not need prologue/epilogue sequences generated by the compiler. It is up to the programmer to provide these sequences.
model (model-name)
Use this attribute on the M32R/D to set the addressability of an object, and the code generated for a function. The identifier model-name is one of small, medium, or large, representing each of the code models. Small model objects live in the lower 16MB of memory (so that their addresses can be loaded with the ld24 instruction), and are callable with the bl instruction.
Medium model objects may live anywhere in the 32-bit address space (the compiler will generate seth/add3 instructions to load their addresses), and are callable with the bl instruction.
Large model objects may live anywhere in the 32-bit address space (the compiler will generate seth/add3 instructions to load their addresses), and may not be reachable with the bl instruction (the compiler will generate the much slower seth/add3/jl instruction sequence).
far
On 68HC11 and 68HC12 the far attribute causes the compiler to use a calling convention that takes care of switching memory banks when entering and leaving a function. This calling convention is also the default when using the -mlong-calls option. On 68HC12 the compiler will use the call and rtc instructions to call and return from a function.
On 68HC11 the compiler will generate a sequence of instructions to invoke a board-specific routine to switch the memory bank and call the real function. The board-specific routine simulates a call. At the end of a function, it will jump to a board-specific routine instead of using rts. The board-specific return routine simulates the rtc.
near
On 68HC11 and 68HC12 the near attribute causes the compiler to use the normal calling convention based on jsr and rts. This attribute can be used to cancel the effect of the -mlong-calls option.
You can specify multiple attributes in a declaration by separating them by commas within the double parentheses or by immediately following an attribute declaration with another attribute declaration.
Some people object to the __attribute__ feature, suggesting that ISO C's #pragma should be used instead. At the time __attribute__ was designed, there were two reasons for not doing this.
  1. It is impossible to generate #pragma commands from a macro.
  2. There is no telling what the same #pragma might mean in another compiler.
These two reasons applied to almost any application that might have been proposed for #pragma. It was basically a mistake to use #pragma for anything.
The ISO C99 standard includes _Pragma, which now allows pragmas to be generated from macros. In addition, a #pragma GCC namespace is now in use for GCC-specific pragmas. However, it has been found convenient to use __attribute__ to achieve a natural attachment of attributes to their corresponding declarations, whereas #pragma GCC is of use for constructs that do not naturally form part of the grammar. See Miscellaneous Preprocessing Directives.


Reference:

https://gcc.gnu.org/onlinedocs/gcc-3.3/gcc/Function-Attributes.html