I've probably got a cheek, being new-ish to Arduino & C++, but this morning I was looking for help on the backslash character in the Forum. The character seemed to be related to verify errors I was getting in a particular sketch from the web.
Failing finding anything in the Forum that I could grasp, I ended up looking into both my C++ textbooks to see what it was all about.
I still didn't quite understand what I was reading, so I took a deep breath and posted my problem in the Programming Questions section ("Verify errors in Arduino project"). It took another 30 minutes to write up and proof read, and I got an excellently concise answer an hour or so later (thanks, Whandall) which sorted me out.
During the searching process, I noticed there were over half a MILLION posts in this section alone, and started wondering, would it not save everyone an awful lot of typing if there were a "Proper" Help offering in the IDE, a bit like, for instance, F1 (Help) in Microsoft progams, where you can drill down fairly quickly in one place, rather than getting transferred to a general-purpose Google-style website search?
I appreciate the help there already is on the IDE, but I think it should go further & deeper, and be set up as a CHM file.
Do you want the IDE to give help on Arduino specific functions, C functions or C++ functions ?
The Arduino functions are documented in the reference section and there is tons of help available on C and C++ on the Web. A Google search for "C backslash character" give the following as its first hit Escape sequences in C - Wikipedia which has a comprehensive list of the C escape sequences.
If you would like to enhance the Arduino IDE to provide context sensitive help then please feel free to do so. The best it does at the moment is to allow you to highlight an Arduino function name, right click on it and go straight to the reference page for the function.
UKHeliBob:
Do you want the IDE to give help on Arduino specific functions, C functions or C++ functions ?
The Arduino functions are documented in the reference section and there is tons of help available on C and C++ on the Web. A Google search for "C backslash character" give the following as its first hit Escape sequences in C - Wikipedia which has a comprehensive list of the C escape sequences.
If you would like to enhance the Arduino IDE to provide context sensitive help then please feel free to do so. The best it does at the moment is to allow you to highlight an Arduino function name, right click on it and go straight to the reference page for the function.
HeliBob,
You're right. I knew when I posted that it would take a massive effort to implement, and anyway, you'd need a raft of coding experts to actually generate all the required text.
As you said, there is lots and lots out on the web about this specific (backslash) character, but what I saw didn't help. It turns out the compiler uses the \ for its own purposes, and not, for instance, as an escape sequence.
I suppose what I want is to be spoon-fed from a help file rather than getting links to web sites which may or may not have Arduino in mind. However, I don't know how to write help files to start with. How does one go about getting the Arduino IDE to provide context sensitive help?
You can write tools that work on/with the code in the IDE,
there is an example of the mechanism in the tools directory of the Arduino installation, which works on highlighted text.
Mangler.java
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Processing project - http://processing.org
Copyright (c) 2008 Ben Fry and Casey Reas
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.transformers.supermangletron;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JOptionPane;
import processing.app.Editor;
import processing.app.tools.Tool;
/**
* Example Tools menu entry.
*/
public class Mangler implements Tool {
Editor editor;
public void init(Editor editor) {
this.editor = editor;
}
public String getMenuTitle() {
return "Mangle Selection";
}
public void run() {
String sketchName = editor.getSketch().getName();
Object[] options = { "Yes, please", "No, thanks" };
int result = JOptionPane.showOptionDialog(editor,
"Is " + sketchName +
" ready for destruction?",
"Super Mangle Tron",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[1]);
if (result == JOptionPane.YES_OPTION) {
mangleSelection();
}
}
protected void mangleSelection() {
if (editor.isSelectionActive()) {
String selection = editor.getSelectedText();
char[] stuff = selection.toCharArray();
// Randomly swap a bunch of characters in the text
for (int i = 0; i < stuff.length / 10; i++) {
int a = (int) (Math.random() * stuff.length);
int b = (int) (Math.random() * stuff.length);
if (stuff[a] == '\n' || stuff[b] == '\n') {
continue; // skip newline characters
}
stuff[a] = selection.charAt(b);
stuff[b] = selection.charAt(a);
}
editor.startCompoundEdit();
editor.setSelectedText(new String(stuff));
editor.stopCompoundEdit();
editor.statusNotice("Now that feels better, doesn't it?");
} else {
editor.statusError("No selection, no dice.");
}
}
}
Eclipse (with Arduino plugin) may be a better solution than extending the Arduino IDE.
Pat-The-Pirate:
During the searching process, I noticed there were over half a MILLION posts in this section alone, and started wondering, would it not save everyone an awful lot of typing if there were a "Proper" Help offering in the IDE, a bit like, for instance, F1 (Help) in Microsoft progams, where you can drill down fairly quickly in one place, rather than getting transferred to a general-purpose Google-style website search?
Do it! Go nuts! The IDE is written mostly in Java, and the code is on github and is open source. Fork the code, write a proper help system, and then offer your edits to be merged back into the main project as a gihub pull request.
Of course, someone is going to have to - you know - write the content of that help system. Hopefully you will come up with some way of organising your new hel system so that people can add that content over time.
I knew this was opening a can of proverbials. I'll go out to Waterstones and buy "Java For Dummies" and ponder my future. Or maybe buy the Arduino book as was suggested in another post.
It's just I've seen a lot of posts asking for things in the "wrong" place, especially in the Programming Questions; I think a lot of folk don't use flow charts to start describing their projects, and I see very few electrical schematics, which I tend to run on best. This morning a guy posted looking for someone to help code his entire project, which looked to me as if he needed to sit down and describe it to himself first.
So I had to refine my search for the elusive backslash to the point where it all got a bit pointless. The backslash answer was probably in a post somewhere, but I started to feel that I wasn't going to stumble over it, and I then posted myself, knowing that the answer was buried amongst the 530k+ posts. Or maybe not.
sigh
To sum up: this magic Help file will probably only happen if Atmel throw a dozen C* experts with linguistic and Java skills at it. They, after all, are the ones who like to sell Arduinos.
I found the backslash in someone elses sketch and eventually discovered that, in a multi-line macro, the backslashes tell the compiler (preprocessor) to ignore the next newline and to treat the next line as part of the macro definition.
In the sketch containing backslashes, what actually happened was that my cut-paste operation into the IDE caused the sketch to be double-line-spaced, which completely threw the compile out of kilter where it was going through the macro section.
Knowing nothing of macros, I had no idea how this could happen.
And I don't know why it got double spaced, only that one can stop it happening if instead of pasting directly into the IDE, you paste into Microsoft word, and then copy from Word into the IDE. And it only seems to upset code containing macros.
My understanding of escape sequences is e.g. \t is a TAB etc. As an afterthought, the sketch came into Word pre-formatted as a Table, and I used the Convert-Table-To-Text utility in Word to rid it of whatever formatting the website / HTML had been applying.
I hope this makes sense, as it has been a month-long battle to try and get the sketch to compile.
in a multi-line macro, the backslashes tell the compiler (preprocessor) to ignore the next newline and to treat the next line as part of the macro definition.
This is standard C, not anything special for the compiler (or preprocessor). Backslash at the end of a line tells the compiler/preprocessor to ignore the newline that follows and continue with the following line.
Not sure why your double-spacing occurred. That would certainly be a problem and could upset more than macros.
OK, gotcha.
The backslash when used in a multi-line macro is handled by the preprocessor before the C compiler itself gets to do its thing - it is not part of the C language itself. As you've discovered, you have to make sure that if a macro has continuation lines, every line must be continued - a blank line will be interpreted as the end of the macro.
Escape sequences in C strings, such as \t \n etc are part of the C language syntax and are handled by the C compiler. In these cases, the backslash does not occur at the end of the line.
Well, I suggested to Littlebits that they should put the sketch on the website as a file, which they have now done. It now comes down single spaced and so the problem has been put to bed.
I've also suggested they place a "Known Working Copy" of the Midi library as Midi.zip on the site, as it seems the library can be "updated" but lose backwards compatibility. (I may be wrong here, but it took me ages to find a Midi library that worked with this sketch, and other older sketches).
I really appreciate the time people (e.g. Paul / Whandall / el_Supremo / vaj and others) are spending getting people like myself out of difficulty.
Pat-The-Pirate:
So I had to refine my search for the elusive backslash to the point where it all got a bit pointless. The backslash answer was probably in a post somewhere, but I started to feel that I wasn't going to stumble over it, and I then posted myself, knowing that the answer was buried amongst the 530k+ posts. Or maybe not.
I think your problem was that you were limiting your search to this site. Don't do that for general C or C++ questions. Use google and search the wider web.