Cedet cannot properly parse the time.h under /usr/include - emacs

I configured my cedet almost the same with http://alexott.net/en/writings/emacs-devenv/EmacsCedet.html.
Thanks alexott , most of the time it works well, but I found that it can not well parse the tm struct in /usr/include/time.h.
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main(void){
struct tm times;
FILE file;
}
When using M-x semantic-ia-fast-jump, the struct FILE is correct, but semantic finds the struct tm in wchar.h, not in time.h.
The problem seems to be there is a forward declaration in wchar.h for the struct tm.

In my copy of time.h, it appears that the symbol __BEGIN_NAMESPACE_STD is showing up in front of the struct declaration, and is befuddling the parser. You can fix that quickly by just adding that and __END_NAMESPACE_STD to the variable semantic-lex-c-preprocessor-symbol-map as mapping to empty. Then delete your semanticdb cache files (in ~/.semanticdb) related to time.h, or just everything in /usr/include, and restart emacs. time.h should get reparsed, and things should work ok for time.h after that... unless you want to use std::tm or something.

Related

Using C macros in Swift

Have my own macro defined in myProject.pch file,
For example:
#define Enable_Analytics
And i want to enclose few statements of code at multiple places inside
#ifdef Enable_Analytics
// Code statements which has to executed only if Enable_Analytics is defined
#endif
This is useful to include/remove code based on the macro.
In Objective-C this works but in swift i get error. How to use #ifdef in swift?
You can call the C preprocessor on just about and kind of file even if it is not C or a C like language.
It is usually available as cpp on most Unix like systems. Just run cpp your-file.swift and the C preprocessor should preprocess the file just as it would C.
However I do not know of a way to make the preprocessor use defines within a project file. So you probably will have to manually specify them on the command line like -DMACRO_NAME=somevalue.
Alternatively you could #include a file containing the defines within each of your swift files and the preprocessor will insert them.

Using hotstring to create code snippets

I used AutoHotKey recently, where I made a hotstring which would create a piece of code so that I can increase my productivity.
Here is the hotstring:
::basic::#include <iostream> int main(){}
But the output is:
#include <iostream> int main()
This script didn't include the curly braces I reqiured.
So, I want this to run perfectly.
Try:
::basic::#include <iostream> int main(){{}{}}

when should I #define NO_XSLOCKS

NO_XSLOCKS allows the usage of some error checking macros in XS code when combined with #include XSUB.h. However, its use seems to go beyond that. It was recently suggested that I add it to my XS file for better compatibility with ActiveState perl, with this issue given as an example.
What else does #define NO_XSLOCKS do, and when should I use it in my XS code?

How to have more than one include in org babel?

I am working with C++ in org babel and would like to know how to format the includes so that I can list more than one.
Here's what I'm trying (that fails)
#+BEGIN_SRC C++ :includes <cstdio> :includes <iostream> :includes <string>
using namespace std;
printf("Hello ");
cout << "world\n";
#+END_SRC
In this case both printf and cout are undeclared in this scope. I can drop the unnecessary :includes <string> from the headers and the cout doesn't kick up an error, so it seems like only the last :includes counts. I have tried loading multiple includes into the same line using nothing, commas and spaces as delimiters and I always get an error about extra tokens at the end of the include directive. I have also tried using :includes+ in case that worked on the header line, but it didn't.
I'm fairly certain that what I'm trying to do should be possible because it says in the documentation that
:includes
(C & CC+ only) accepts either a single string name, or a list of names of files to #include in the execution of the code block
Org-version: 8.2.7-4-g880362-elpa
EDIT:
It's worth noting that other header arguments can just be strung together (i.e. :results raw drawer will produce unformatted results in a drawer), so there's a decent chance that this is a bug. Using :include <cstdio> <iostream> produces a compiler error that there's an extra token at the end of the #include <cstdio> line.
EDIT 2:
Turns out it's actually a bug in org, so it's been submitted.
After some experimenting, during which I noticed that some error messages look fairly lispy, and using the superficial knowledge I have of Lisp, I found the answer:
#+begin_src C++ :includes '("<math.h>" "<iostream>" "<algorithm>")
// Freely use symbols from those headers
#+end_src
Another issue that I'm having is that I can only get it to execute if I capitalize C++ but I only get syntax highlighting if I use minuscules ("c++"). Pure joy.

Is there a way to replace an already defined preprocessor identifier?

I have a library that has several options defined as this:
#define shouldShowToolbar YES
#define shouldAlignToLeft YES
etc..
and I'm looking for a way to actually replace those from outside (without modifying the library, because the future updates will break it). Is it possible, or am I doomed to change the library source code (which I do have) every time an update comes out.
There is #undef
#include "library_header.h" /* Which defines the macro. */
#undef shouldShowToolbar /* You undef it. */
#define shouldShowToolbar NO /* If you want, you can redefine it. */
http://gcc.gnu.org/onlinedocs/cpp/Undefining-and-Redefining-Macros.html
If you don't want a particular macro to take effect for a section of code and you know that macro name too, you can use
#undef shouldShowToolbar
/* Your code */
#define shouldShowToolbar
This wont totally undef the macro, cos you never know which part of your code might actually want it
These are values that are hardcoded at compile time. If you compile the library with your project then you should be able to redefine them in a file that compiles later in the compile list, I think there is a special keyword for it. Otherwise it is like saying I want to replace YES in the library.
As far as i know, preprocessor directives executes before compilation. So after that, there's no chance to change something.