C++ :: Leading Underscore Reserved For Implementation
Feb 6, 2012
I've always been bothered when people say "don't name your variables with a leading underscore, it is reserved by the implementation", so I decided to ask this once and for all.
The actual standard says:
17.6.4.3.2 Global names [global.names]
1 Certain sets of names and function signatures are always reserved to the implementation:
- Each name that contains a double underscore _ _ or begins with an underscore followed by an uppercase letter (2.12) is reserved to the implementation for any use.
- Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace.
Unless I'm mistaken I read this as:
Words like "__foo" or "_BAR" are strictly off limits, as the implementation may have used it as a macro.Words like "_foo", when used for things such a member variables, or scoped variables on the stack are fine. The implementation only gets to use those as global functions inside mainspace.
So my question is this: While using leading underscores is generally frowned upon, is it, strictly according to the standard, wrong?
Calculate the reversed numbers from the input. Reversed number is a number written in arabic numerals but the order of digits is reversed (e.g. 543 reversed would be 345). You need to add two reversed numbers and output their reversed sum. Of course, the result is not unique because any particular number is a reversed form of several numbers (e.g. 21 could be 12, 120 or 1200 before reversing). Thus you must assume that no zeros were lost by reversing (e.g. assume that the original number was 12).
Input
The input consists of N cases (equal to about 10000). The first line of the input contains only positive integer N. Then follow the cases. Each case consists of exactly one line with two positive integers separated by space. These are the numbers you are to reverse and add together.
Output
For each case, print exactly one line containing only one integer - the reversed sum of two reversed numbers (Get the sum of the 2 integers that have been reverses, then reverse that sum also). Omit any leading zeros in the output.
Right now I'm thinking that it can't be done without converting the numbers to a string because I have been working on this for days and can't find a answer.
I am trying to remove the leading zeros of the number user enters so 000002 will turn into 2. However, I am getting an error saying Segmentation fault (core dumped)
#include <stdio.h> #include <string.h> int main(){ char *str; scanf("%c", *str);
With the loop below, is there a way to display the actual number without the leading zeros (scientific notation) or will it just display 0 since there are so many leading zeros?
num = 1; while (num > 0){ num /= 2; } cout << num;
I have a program that I'm making and I want to have the completion of one function lead to another function. So once one equation is done, I want for another equation in a different function to be completed. For example, in my program, I did this:
void Function1() { int a ; a = 4 + 2 ; //For example //now, go to another function, with the value of variable a
[Code] ....
Why doesn't this work, and, what will? When I compile it in Code::Blocks, the error message given is:
I have to develop minimalistic implementation of RSA algorithm in C for an embedded device.
I'm doing that for two days but I have run into a problem. The N modulus is the limitation for the maximum message value to be encrypted with RSA.
For example theoretically RSA-1024 can encrypt/decrypt messages 1024 bits long but I still cannot understand how to choose p and q values to produce N == pow(2, 1024).
Is it possible to encrypt/decrypt 1024 bits long messages in practice if the N < pow(2, 1024)?
I was trying to implement Big Integer Implementation. I wanted to start with the basic operation of addition. I am having some problems with operator overloading part
I was looking at this tutorial: [URL] ..... And I was wondering if implementing it in MVC would be pretty much the same way? How would I display feed items in the views page using?
I tried something like:
ReaderModel Reader = new ReaderModel(); Collection<Rss.Item> List; List = Reader.GetFeed(); ViewData["RssItems"] = List;
// then in index.cshtml @foreach(Collection<Rss.Item> items in ViewData["RssItems"]) { <h3>items.Title</h3> ... }
I don't think this is right as I'm getting those red error lines...
I've been working on creating a simulator to crash two galaxies together as part of a project to stress test a CUDA super computer. I've got a long way to go and am currently just working on correctly simulating n-body gravity functions. First I will use this to simulate the cores of the galaxies (the black holes) and eventually the stars.
So long story short I'm working on the beginnings of a gravity simulator. At this point I found some basic code that works well but doesn't quite give the effect I'm looking for.
The code below only pulls each object towards each other like a spring faster and faster until they shoot off into infinity. I try to give one of my bodies an initial velocity to get it to orbit another, but it always just shoots straight at the other body. I'm thinking I need to factor in inertia so that the initial velocity doesn't just get calculated away really fast by the other calculations.
I'm really looking for a bit of direction to get a real gravity simulator with orbits and such working right so eventually I can scale it up to a galaxy, throw in 100B stars and let the CUDA run for a month..
As you can see, I'm calculating all the bodies in a vector called "galaxies" with each other, and doing a basic gravity calculation to it. The update_position function simply takes the calculated acceleration and uses it to calculate the velocity and position based on the "elapsedTime".
I think I need to use the Varlet or Runge-Kutta integration methods, after doing a bit more research.
Output to terminal: 0 2 3 1 4 5 but it should be: 0 2 4 5 3 1
Here's my code:
#include<stdio.h> #include<assert.h> /* maxVertices represents maximum number of vertices that can be present in the graph. */ #define maxVertices 100 void Dfs(int graph[][maxVertices], int *size, int presentVertex,int *visited)
I am trying to implement a stack class which has struct data type as its private member. I am getiing the following error ,
bash-3.2$ g++ stack_str_arr.cpp stack_str_arr.cpp: In member function ‘void stack::push(int)’: stack_str_arr.cpp:39: error: ‘top’ was not declared in this scope stack_str_arr.cpp: At global scope: stack_str_arr.cpp:43: error: no ‘void stack::display()’ member function declared in class ‘stack’
Code:
#include<iostream> using namespace std; #define MAX 5 class stack { public : stack();
I'm implementing a 4x4 matrix class and all is going well until the inverse function turned up. I'm trying to implement the inverse function, but I can't seem to get my head around it.
I've tried the internet, but found nothing useful. Also, I've looked into source code of other programs/libraries that implement a matrix class, but the code is unreadable.
How I can implement this damn 4x4 inverse function? I know the process of inversion, but putting that process into code is proving quite a challenge.
In addition, I do have some code, but it's unmanageable and inefficient at the moment. If you want to see it, just ask.
Additional question(s): What applications does the inverse matrix have in 3-D?
I'd like te have a heap which contains any item inserted by me. However, when I insert the values, if I delete the min value of this coded heap twice, I get the min value uncorrect.I could not find where the mistake is.
Code:
void BinaryHeap::percolateDown(int hole) { int child = hole*2; while (child < size) {
I was trying to implement a hash function in c++. This is just for learning purposes and not for a class project or assignment question. I had some questions before I started programming it:
1) Is it meaningful to have a hash function which maps string to string, string to int, int to int, float to int? 2) Can we have a template implementation which does element to element hashing?
I looked at several sources for a clear understanding of concepts and implementation technique but could not find a good source for reading about hashing.
I created a structure Vector and implement some functions to make the new defined type (vector) dynamically allocated and resized (inspired from the C++ implementation of the dynamic arrays : vector). I need to assign a structure to every vector element but I am not sure that I am doing it right:
here is the structure that I've defined:
typedef struct { void** mem; // to make this parametrizable I want the void* to point to a Structure (referenced with * a pointer) unsigned long elems; unsigned long elemsize; //element size
[Code] ....
I believe I have serious problems with pointers, values and dereferencing a pointer.
So I'm going through and trying to do a recursive implementation of a Heap. I keep getting access violations for some reason on my sifts (_siftUp) - even though I'm trying to insert into sub[0] (currSize = 0 in the constructor). I don't think either of my sifts are implemented correctly, are they?