Search Results

Search found 9 results on 1 pages for 'arunsaha'.

Page 1/1 | 1 

  • Syntax highlighting in MS Word document

    - by ArunSaha
    I want to insert some C/C++ source code into a Microsoft Word document. I have no problem in copying the code from source file and pasting into Word. I can do fixed-width. But, in Word, I see the code in black-and-white format; I loose the syntax highlighting as I get in the source code editor (for me, gvim). So, my question is, is there any way to do syntax highlighting of C/C++ source code in MS Word?

    Read the article

  • Question on boost array initializer

    - by ArunSaha
    I am trying to understand the boost array. The code can be read easily from author's site. In the design rationale, author (Nicolai M. Josuttis) mentioned that the following two types of initialization is possible. boost::array<int,4> a = { { 1, 2, 3 } }; // Line 1 boost::array<int,4> a = { 1, 2, 3 }; // Line 2 In my experiment with g++ (version 4.1.2) Line 1 is working but Line 2 is not. (Line 2 yields the following: warning: missing braces around initializer for 'int [4]' warning: missing initializer for member 'boost::array<int, 4ul>::elems' ) Nevertheless, my main question is, how Line 1 is working? I tried to write a class similar to array.hpp and use statement like Line 1, but that did not work :-(. Can somebody explain me? Is there some boost specific thing happening in Line 1 that I need to be aware of? Thanks in advance. Regards,

    Read the article

  • g++ How to get warning on ignoring function return value

    - by ArunSaha
    lint produces some warning like: foo.c XXX Warning 534: Ignoring return value of function bar() From the lint manual 534 Ignoring return value of function 'Symbol' (compare with Location) A function that returns a value is called just for side effects as, for example, in a statement by itself or the left-hand side of a comma operator. Try: (void) function(); to call a function and ignore its return value. See also the fvr, fvo and fdr flags in §5.5 "Flag Options". I want to get this warning, if there exists any, during compilation. Is there any option in gcc/g++ to achieve this? I had turned on -Wall but that apparently did not detect this.

    Read the article

  • C++ std::vector insert segfault

    - by ArunSaha
    I am writing a test program to understand vector's better. In one of the scenarios, I am trying to insert a value into the vector at a specified position. The code compiles clean. However, on execution, it is throwing a Segmentation Fault from the v8.insert(..) line (see code below). I am confused. Can somebody point me to what is wrong in my code? #define UNIT_TEST(x) assert(x) #define ENSURE(x) assert(x) #include <vector> typedef std::vector< int > intVector; typedef std::vector< int >::iterator intVectorIterator; typedef std::vector< int >::const_iterator intVectorConstIterator; intVectorIterator find( intVector v, int key ); void test_insert(); intVectorIterator find( intVector v, int key ) { for( intVectorIterator it = v.begin(); it != v.end(); ++it ) { if( *it == key ) { return it; } } return v.end(); } void test_insert() { const int values[] = {10, 20, 30, 40, 50}; const size_t valuesLength = sizeof( values ) / sizeof( values[ 0 ] ); size_t index = 0; const int insertValue = 5; intVector v8; for( index = 0; index < valuesLength; ++index ) { v8.push_back( values[ index ] ); } ENSURE( v8.size() == valuesLength ); for( index = 0; index < valuesLength; ++index ) { printf( "index = %u\n", index ); intVectorIterator it = find( v8, values[ index ] ); ENSURE( it != v8.end() ); ENSURE( *it == values[ index ] ); // intVectorIterator itToInsertedItem = v8.insert( it, insertValue ); // line 51 // UNIT_TEST( *itToInsertedItem == insertValue ); } } int main() { test_insert(); return 0; } $ ./a.out index = 0 Segmentation Fault (core dumped) (gdb) bt #0 0xff3a03ec in memmove () from /platform/SUNW,T5140/lib/libc_psr.so.1 #1 0x00012064 in std::__copy_move_backward<false, true, std::random_access_iterator_tag>::__copy_move_b<int> (__first=0x23e48, __last=0x23450, __result=0x23454) at /local/gcc/4.4.1/lib/gcc/sparc-sun-solaris2.10/4.4.1/../../../../include/c++/4.4.1/bits/stl_algobase.h:575 #2 0x00011f08 in std::__copy_move_backward_a<false, int*, int*> (__first=0x23e48, __last=0x23450, __result=0x23454) at /local/gcc/4.4.1/lib/gcc/sparc-sun-solaris2.10/4.4.1/../../../../include/c++/4.4.1/bits/stl_algobase.h:595 #3 0x00011d00 in std::__copy_move_backward_a2<false, int*, int*> (__first=0x23e48, __last=0x23450, __result=0x23454) at /local/gcc/4.4.1/lib/gcc/sparc-sun-solaris2.10/4.4.1/../../../../include/c++/4.4.1/bits/stl_algobase.h:605 #4 0x000119b8 in std::copy_backward<int*, int*> (__first=0x23e48, __last=0x23450, __result=0x23454) at /local/gcc/4.4.1/lib/gcc/sparc-sun-solaris2.10/4.4.1/../../../../include/c++/4.4.1/bits/stl_algobase.h:640 #5 0x000113ac in std::vector<int, std::allocator<int> >::_M_insert_aux (this=0xffbfeba0, __position=..., __x=@0xffbfebac) at /local/gcc/4.4.1/lib/gcc/sparc-sun-solaris2.10/4.4.1/../../../../include/c++/4.4.1/bits/vector.tcc:308 #6 0x00011120 in std::vector<int, std::allocator<int> >::insert (this=0xffbfeba0, __position=..., __x=@0xffbfebac) at /local/gcc/4.4.1/lib/gcc/sparc-sun-solaris2.10/4.4.1/../../../../include/c++/4.4.1/bits/vector.tcc:126 #7 0x00010bc0 in test_insert () at vector_insert_test.cpp:51 #8 0x00010c48 in main () at vector_insert_test.cpp:58 (gdb) q

    Read the article

  • C++ using typedefs in non-inline functions

    - by ArunSaha
    I have a class like this template< typename T > class vector { public: typedef T & reference; typedef T const & const_reference; typedef size_t size_type; const_reference at( size_t ) const; reference at( size_t ); and later in the same file template< typename T > typename vector<T>::const_reference // Line X vector<T>::at( size_type i ) const { rangecheck(); return elems_[ i ]; } template< typename T > reference // Line Y vector<T>::at( size_type i ) { rangecheck(); return elems_[ i ]; } Line X compiles fine but Line Y does not compile. The error message from g++ (version 4.4.1) is: foo.h:Y: error: expected initializer before 'vector' From this I gather that, if I want to have non-inline functions then I have to fully qualify the typedef name as in Line X. (Note that, there is no problem for size_type.) However, at least to me, Line X looks clumsy. Is there any alternative approach?

    Read the article

  • Why size_t arguments in template declaration need to be const?

    - by ArunSaha
    I can have std::bitset< 10 > bitsetA; or const size_t LengthB = 20; std::bitset< LengthB > bitsetB; without any problem. But, if the length is not const size_t LengthC = 30; std::bitset< LengthC > bitsetC; // Line 30, say I face the following compilation error 'LengthC' cannot appear in a constant-expression template argument 1 is invalid What is the reason for that? What would be the problem, for compiler and for user code, if line 30 was to be accepted? Is it because LengthC might have some alias?

    Read the article

  • C++ Templates: Convincing self against code bloat

    - by ArunSaha
    I have heard about code bloats in context of C++ templates. I know that is not the case with modern C++ compilers. But, I want to construct an example and convince myself. Lets say we have a class template< typename T, size_t N > class Array { public: T * data(); private: T elems_[ N }; }; template< typename T, size_t N > T * Array<T>::data() { return elems_; } Further, let's say types.h contains typedef Array< int, 100 > MyArray; x.cpp contains MyArray ArrayX; and y.cpp contains MyArray ArrayY; Now, how can I verify that the code space for MyArray::data() is same for both ArrayX and ArrayY? What else I should know and verify from this (or other similar simple) examples? If there is any g++ specific tips, I am interested for that too. PS: Regarding bloat, I am concerned even for the slightest of bloats, since I come from embedded context.

    Read the article

  • What is the result of "new int[ 0 ]"? [closed]

    - by ArunSaha
    Possible Duplicates: What does zero-sized array allocation do/mean? C++ new int[0] — will it allocate memory? int * p; p = new int[ 0 ]; What is the expected outcome when new is called for zero number of elements? Is the outcome defined or undefined? Further, is it okay to call delete [] p; on that pointer? What is the intuition/analogy to this situation of pointer to an array of zero elements? Thanks in advance. Regards, Arun

    Read the article

  • How to print size_t variable portably?

    - by ArunSaha
    I have a variable of type size_t, and I want to print it using printf(). What format specifier do I use to print it portably? In 32-bit machine, %u seems right. I compiled with g++ -g -W -Wall -Werror -ansi -pedantic, and there was no warning. But when I compile that code in 64-bit machine, it produces warning. size_t x = <something>; printf( "size = %u\n", x ); warning: format '%u' expects type 'unsigned int', but argument 2 has type 'long unsigned int' The warning goes away, as expected, if I change that to %lu. The question is, how can I write the code, so that it compiles warning free on both 32- and 64- bit machines? Edit: I guess one answer might be to "cast" the variable into an unsigned long, and print using %lu. That would work in both cases. I am looking if there is any other idea. (C, C++)

    Read the article

1