To whom it may concern,
I typed #ifndef DEMO_H_ and press enter, and #endif auto completed with a C++ comment along with preprocessor macro name.
#ifndef DEMO_H_
#endif // DEMO_H_
Should not add or generate a C style comment line when it's used with C code?
Thank you.
P.S.: It works OK if you compile it as C99, but not as C90.
Try: src/plugins/codecompletion/codecompletion.cpp line 1601 and src/plugins/contrib/SmartIndent/SmartIndentCpp.cpp line 566.
First of all, Alpha thank you so much for pointing out which files and lines should get implemented; much appreciated mate.
My concept from mixing C code with C++ is to use preprocessor conditionals, but I don't think it would work, as the existing code will compile with C++ and not with C.
For example, at codecompletion.cpp lines 1600-1602 we see the following:
if (!pp.GetMatch(control->GetLine(ppLine), 2).IsEmpty())
itemText.Append(wxT(" // ") + pp.GetMatch(control->GetLine(ppLine), 2));
break;
Now, even if you try something like the following below, it won't work as it depends on C++ in order to compile wxWidgets:
if (!pp.GetMatch(control->GetLine(ppLine), 2).IsEmpty())
#if defined(__cplusplus)
itemText.Append(wxT(" // ") + pp.GetMatch(control->GetLine(ppLine), 2));
#else
itemText.Append(wxT(" /* ") + pp.GetMatch(control->GetLine(ppLine), 2) + wxT(" */ "));
#endif
break;
What would be your way to ask the system to check whether it's C or C++?
Cheers.
There is no good/global way defined (yet) to determine between C and C++. (Code::Blocks treats them as the same thing most of the time.) This is how it is currently done:
HighlightLanguage EditorColourSet::Apply(cbEditor* editor, HighlightLanguage lang)
{
if (!editor)
return HL_NONE;
if (lang == HL_AUTO)
lang = GetLanguageForFilename(editor->GetFilename());
const bool isC = ( Manager::Get()->GetConfigManager(wxT("editor"))->ReadBool(wxT("no_stl_in_c"), true)
&& lang == GetHighlightLanguage(wxT("C/C++"))
&& editor->GetFilename().Lower().EndsWith(wxT(".c")) );
Apply(lang, editor->GetLeftSplitViewControl(), isC);
Apply(lang, editor->GetRightSplitViewControl(), isC);
return lang;
}
void CodeCompletion::UpdateEditorSyntax(cbEditor* ed)
{
if (!Manager::Get()->GetConfigManager(wxT("code_completion"))->ReadBool(wxT("/semantic_keywords"), false))
return;
if (!ed)
ed = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
if (!ed || ed->GetControl()->GetLexer() != wxSCI_LEX_CPP)
return;
TokenIdxSet result;
int flags = tkAnyContainer | tkAnyFunction;
if (ed->GetFilename().EndsWith(wxT(".c")))
flags |= tkVariable;
m_NativeParser.GetParser().FindTokensInFile(ed->GetFilename(), result, flags);
[...]
}
void EditorManager::CollectDefines(CodeBlocksEvent& event)
{
[...]
defines.Add(wxT("__cplusplus"));
for (FilesList::iterator it = lst->begin(); it != lst->end(); ++it)
{
if ((*it)->relativeFilename.EndsWith(wxT(".c")))
{
defines.RemoveAt(defines.GetCount() - 1); // do not define '__cplusplus' if even a single C file is found
break;
}
}
[...]
}
The check should ask the editor to see if it has C++ or C lexing, I think there is a global function that can tell what is the language somewhere in the global headers.
For reference purposes, the related global is:
FileType FileTypeOf(const wxString& filename)