Thursday, January 30, 2014

i really need help

Newsgroup: comp.lang.c++

Subject: i really need help

From: mary8shtr@...

Date: Thu, 30 Jan 2014 07:34:04 -0800 (PST)



Hi.I joined recently to this group .I want write a program in c++ language.one program in c++ that receive two char array from user and print all of state built by this tow arryas.for example users enter "abc" and "mn".program should show abcmn , abmnc , amnbc , mnabc ,mabcn ,manbc, mabnc , ambnc ,ambcn ,abmcn as output.pleas answer me.I very thought on this solution.but I couldn't solve it.and i need it early.I thanks very much if anyone answer me faster.







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1cB0tAa

View all the progranning help forums at:

http://ift.tt/1dP9txN

Tuesday, January 28, 2014

How does the name lookup work in this case?

Newsgroup: comp.lang.c++

Subject: How does the name lookup work in this case?

From: Peter <pilarp@...>

Date: Tue, 28 Jan 2014 12:47:31 -0800 (PST)



Consider this definition (namespace and class share the same name):



namespace Foo

{

int x;



class Foo

{

public:

static int x;

};



int Foo::x;

}



I wondered what Foo::x would refer to with "using" directive used for namespace Foo: a global variable x in namespace Foo or static member of class Foo? Basically, I assumed the following code would not compile:



int main()

{

using namespace Foo;

Foo::x;

return 0;

}



My reasoning went like this:



- Foo::x is a global variable x from namespace Foo

- Foo::Foo::x is a static member of class Foo from namespace Foo, but since

"using" directive is applied, the namespace name can be omitted, thus Foo::x is also a static member of class Foo

- conclusion: call to Foo::x in main() is ambiguous - it refers to two different entities



However, the compiler I tested it with (one of g++ recent versions) had no trouble disambiguating this: experiments showed Foo::x in main() is interpreted as global variable x in namespace Foo. Moreover, if I remove the definition of global x from namespace Foo, then the compiler emits the following error:



main.cpp: In function 'int main()':

main.cpp:16:4: error: 'x' is not a member of 'Foo'

Foo::x;



so it doesn't find the static member of class Foo. In order for the compiler to find it I have to qualify it fully as Foo::Foo::x despite the "using namespace Foo;" line. Why? How does the lookup work here?







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1floQ5s

View all the progranning help forums at:

http://ift.tt/1dP9txN

Boost

Newsgroup: comp.lang.c++

Subject: Boost

From: Nick Baumbach <nich@...>

Date: Fri, 17 Jan 2014 15:11:24 +0000 (UTC)



Does anybody use Boost code, what is it.



I mean, it has to make things easier, but it does not looks like, since it

takes hours to compile.







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1b6a8dS

View all the progranning help forums at:

http://ift.tt/1dP9txN

Monday, January 27, 2014

Moving from C++03 to C++11

Newsgroup: comp.lang.c++

Subject: Moving from C++03 to C++11

From: retro54321@...

Date: Sun, 26 Jan 2014 16:06:20 -0800 (PST)





Could someone please suggest a good book (or any kind of resource) for someone who's very familiar with C++03 and who wants to get up to speed with C++11.



(I was considering getting the 4th addition of Bjarne's book, but rather than read about the entire language from start to finish, I just want to focus on the new stuff brought in with C++11).



Rhino







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1f4Mna3

View all the progranning help forums at:

http://ift.tt/1dP9txN

What is the disadvantage with C++ in Embedded systems?

Newsgroup: comp.lang.c++

Subject: Re: What is the disadvantage with C++ in Embedded systems?

From: deepadivakaruni@...

Date: Sat, 25 Jan 2014 08:48:00 -0800 (PST)



i think so c++ is more complicated when compared to c.And also the many keywords are used to perform only one application.







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1glczRs

View all the progranning help forums at:

http://ift.tt/1dP9txN

goto label inside of if statement

Newsgroup: comp.lang.c++

Subject: goto label inside of if statement

From: W Karas <wkaras@...>

Date: Thu, 23 Jan 2014 11:32:13 -0800 (PST)



I was surprised to find that this code:



struct A { A(); ~A(); };



void bar();



void foo(bool f)

{

if (0)

{

LAB: ;

}

else

{

A a;



if (f) goto LAB;



bar();

}

}



will compile without warnings using GCC 4.7.3, even with -Wall and -Wextra .



The point, in case you were wondering, would be a macro-based "named block" pseudo-construct, where the block could be exited from any depth of block nesting, for example:



#define BLOCK(NAME) if (0) { NAME: ; } else

#define EXITBLOCK(NAME) goto NAME;



struct A { A(); ~A(); };



void bar();



void foo(bool f)

{

BLOCK(XYZ)

{

A a;



if (f) EXITBLOCK(XYZ)



bar();

}

}







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1glcAEV

View all the progranning help forums at:

http://ift.tt/1dP9txN

Saturday, January 18, 2014

memory manager to prevent memory leaks

Newsgroup: comp.lang.c++

Subject: memory manager to prevent memory leaks

From: hbdevelop1@...

Date: Fri, 17 Jan 2014 14:49:25 -0800 (PST)



Hello,



I have written a memory tracker to prevent memory leaks in my programs.

The memory tracker meets the following requirements:

r1-Allocate memory using the system's new/new[].

r2-Deallocate memory using the system's delete/delete[].

r3-Log the file name and line where an allocation happens.

r4-When a memory is fred, remove the memory allocation from the log.

r5-At application exit, display the log.



Please find the code at the end of the email.

I have the following questions :



1-

g++ issues the following warning in my operator delete/delete[]: memtracker4.cpp:24:9: warning: deleting ?void*? is undefined [enabled by default]

delete p;

^

Do you have any idea how to correct the code so I don't get the warning ?



2-

To remove tracks of memory added in my operator new/new[], I am using template functions deleteArray and deleteObj.

But I remember in one company I worked in, they were using new(__FILE__,__LINE__) or new[](__FILE__,__LINE__) for allocations and plain delete/delete[] for deallocation.

And I wonder now, how they were removing memory tracks added by their operator new/new[] since they were using plain delete or delete[] for deallocation.

Could anybody please tell me if this is possible ? or were they not removing tracks ?



3-

Please tell me anything else to improve this code.



/////// code ////////



#include <stdio.h>

#include <new>



void AddToLog(long ptr, size_t size,const char * filename, int line)

{

printf("allocation : 0x%08X,%d,%s,%d\n",ptr, size,filename, line);

}



void RemoveFromLog(long ptr)

{

printf("deallocation : 0x%08X\n",ptr);

}



void * operator new(size_t size, const char *filename, int line)

{

void *ptr = ::operator new(size);

AddToLog((long)ptr, size, filename, line);

return(ptr);

};



void * operator new[](size_t size, const char *filename, int line)

{

void *ptr = ::operator new[](size);

AddToLog((long)ptr, size, filename, line);

return(ptr);

};



void operator delete(void *p, const char *filename, int line)

{

RemoveFromLog((long)p);

delete p; //g++ outputs warning: deleting ?void*? is undefined [enabled by default]

};



void operator delete[](void *p, const char *filename, int line)

{

RemoveFromLog((long)p);

delete [] p; //g++ outputs warning: deleting ?void*? is undefined [enabled by default]

};





template<class T> void deleteObj(T *p)

{

RemoveFromLog((long)p);

delete p;

};



template<class T> void deleteArray(T *p)

{

RemoveFromLog((long)p - sizeof(unsigned int));

delete [] p;

};





struct O11

{

int x;

public:

~O11 (){}

};



#define new new(__FILE__,__LINE__)



int main()

{

char *c=new char;

deleteObj<char>(c);



O11 *o=new O11;

deleteObj<O11>(o);



O11 *o1=new O11[10];

deleteArray<O11>(o1);



char *c3=new char[3];

deleteObj<char>(c3);

/*Note that I am treating c3 as a simple object not as array

(which caused my question at http://ift.tt/1mo3EyX)

*/



return 0;

}







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1f1zigo

View all the progranning help forums at:

http://ift.tt/1dP9txN

Tuesday, January 14, 2014

Decoding GIF file in C? [Source code here]

Newsgroup: comp.lang.c++

Subject: Re: Decoding GIF file in C? [Source code here]

From: kirannd1989@...

Date: Wed, 8 Jan 2014 19:23:59 -0800 (PST)



Hi..

i tried compiling this code but there are few undefined Macro/functions like MK_FP().

I am trying it on WIN32, VS2012.. i have made changes accordingly.

Is this solution dependent on any library.

Thanks in advance





On Monday, August 1, 1994 1:02:48 PM UTC+5:30, Cyborg wrote:

> In article <msm6.775622996@...> msm6@... (Muhammad Salman Mughal) writes:

> >

> >Hi there,

> >

> > I am desperately looking for a C code that could decode a GIF file

> > in DOS. Anybody out there who knows how to do it? I will really

> > appreciate any help.

> >

>

>

> The following code is based on a LZW decoder originally coded by Steven A.

> Bennett. All I did is write the code for parsing the GIF format, passing

> the approptiate data to the LZW decoder and writing the code for displaying

> the data on the screen. Both 87a and 89a formats are accepted.

>

> Video BIOS must support VESA functions - the code selects a video mode

> whith a resolution just high enough to display the given GIF file. Max

> resolution is 1280x1024, pictures larger than this will be partially

> displayed. Interlaced GIFs are supported. Program was only tested on my

> video card (Cirrus 5428 VESA Local Bus). It was not intended for public

> release but since I've already written it and the guy i desperate...

>

> Compiles with Borland C++ v3.1

>

> ----------------------- chop here --------------------------

>

> /* Various error codes used by decoder

> * and my own routines... It's okay

> * for you to define whatever you want,

> * as long as it's negative... It will be

> * returned intact up the various subroutine

> * levels...

> */

> #define READ_ERROR -1

> #define WRITE_ERROR -2

> #define OPEN_ERROR -3

> #define CREATE_ERROR -4

> #define OUT_OF_MEMORY -5

> #define BAD_CODE_SIZE -6

>

> #define ISIZE 2048 // image line size

> #define BSIZE 256 // buffer size

> #define PSIZE 768 // pallette size

> #define NULL 0L

> #define MAX_CODES 4095

>

> #include <dos.h>

> #include <conio.h>

> #include <stdio.h>

> #include <stdlib.h>

> #include <string.h>

>

> /* Static variables */

> short curr_size; /* The current code size */

> short clear; /* Value for a clear code */

> short ending; /* Value for a ending code */

> short newcodes; /* First available code */

> short top_slot; /* Highest code for current size */

> short slot; /* Last read code */

>

> /* The following static variables are used

> * for seperating out codes

> */

> short navail_bytes = 0; /* # bytes left in block */

> short nbits_left = 0; /* # bits left in current byte */

> unsigned char b1; /* Current byte */

> unsigned char byte_buff[257]; /* Current block */

> unsigned char *pbytes; /* Pointer to next byte in block */

>

> /* The reason we have these separated like this instead of using

> * a structure like the original Wilhite code did, is because this

> * stuff generally produces significantly faster code when compiled...

> * This code is full of similar speedups... (For a good book on writing

> * C for speed or for space optimisation, see Efficient C by Tom Plum,

> * published by Plum-Hall Associates...)

> */

> unsigned char stack[MAX_CODES + 1]; /* Stack for storing pixels */

> unsigned char suffix[MAX_CODES + 1]; /* Suffix table */

> unsigned short prefix[MAX_CODES + 1]; /* Prefix linked list */

>

> long code_mask[13] = {

> 0x0000,

> 0x0001, 0x0003, 0x0007, 0x000F,

> 0x001F, 0x003F, 0x007F, 0x00FF,

> 0x01FF, 0x03FF, 0x07FF, 0x0FFF

> };

>

> // incremented each time an out of range code is read by the decoder

> int bad_code_count;

>

> unsigned char far *buffer=NULL; // file buffer

> unsigned char far *grgb=NULL; // global rgb table

> unsigned char far *lrgb=NULL; // local rgb table

> unsigned char far *pixels=NULL; // line of pixels to be displayed

> unsigned char far *vid=NULL; // ptr to start of graphics window

> unsigned char background=0; // background color index

> unsigned long offset=0; // offset into graphics window

> unsigned long piclen; // total screen size in pixels

> unsigned int realx; // real picture width

> unsigned int realy; // real picture height

> unsigned int xsize=0; // graphic width

> unsigned int ysize=0; // graphic height

> unsigned int win=0; // window number

> unsigned int granularity=0; // granularity of video window

> unsigned int group=0; // picture group (interlaced or not)

> FILE *fp; // file pointer

>

> /* int get_byte()

> * - This function is expected to return the next byte from

> * the GIF file or a negative number defined in ERRS.H

> */

> int get_byte(){

> unsigned char c;

>

> if(fscanf(fp, "%c", &c)==1)

> return((int)c);

> else

> return(READ_ERROR);

> }

>

> /* int out_line(unsigned char pixels[], int linelen)

> * - This function takes a full line of pixels (one byte per pixel) and

> * displays them (or does whatever your program wants with them...). It

> * should return zero, or negative if an error or some other event occurs

> * which would require aborting the decode process... Note that the length

> * passed will almost always be equal to the line length passed to the

> * decoder function, with the sole exception occurring when an ending code

> * occurs in an odd place in the GIF file... In any case, linelen will be

> * equal to the number of pixels passed...

> */

> int out_line(unsigned char *pixels, int linelen){

> unsigned long segment;

>

> segment=offset&(unsigned long)(granularity-1);

>

> // put pixels on screen

> memmove(vid+segment, pixels, linelen);

> memset(vid+segment+linelen, background, xsize-linelen);

> switch (group) {

> case 0:

> offset+=xsize;

> break;

> case 1:

> offset+=xsize*8;

> if(offset>=piclen){

> group++;

> offset=xsize*4;

> }

> break;

> case 2:

> offset+=xsize*8;

> if(offset>=piclen){

> group++;

> offset=xsize*2;

> }

> break;

> case 3:

> offset+=xsize*4;

> if(offset>=piclen){

> group++;

> offset=xsize;

> }

> break;

> case 4:

> offset+=xsize*2;

> break;

> default:

> break;

> }

>

> // if we've run over a window granularity border, move window position

> if((offset>>12)!=win){

> win=offset>>12;

> asm pusha

> asm mov ax, 0x4f05

> asm mov bx, 0x0000

> asm mov dx, win

> asm int 0x10

> asm popa

> }

> return(1);

> }

>

>

> /* This function initializes the decoder for reading a new image.

> */

> static short init_exp(short size)

> {

> curr_size = size + 1;

> top_slot = 1 << curr_size;

> clear = 1 << size;

> ending = clear + 1;

> slot = newcodes = ending + 1;

> navail_bytes = nbits_left = 0;

> return(0);

> }

>

> /* get_next_code()

> * - gets the next code from the GIF file. Returns the code, or else

> * a negative number in case of file errors...

> */

> static short get_next_code()

> {

> short i, x;

> unsigned long ret;

>

> if (nbits_left == 0)

> {

> if (navail_bytes <= 0)

> {

>

> /* Out of bytes in current block, so read next block

> */

> pbytes = byte_buff;

> if ((navail_bytes = get_byte()) < 0)

> return(navail_bytes);

> else if (navail_bytes)

> {

> for (i = 0; i < navail_bytes; ++i)

> {

> if ((x = get_byte()) < 0)

> return(x);

> byte_buff[i] = x;

> }

> }

> }

> b1 = *pbytes++;

> nbits_left = 8;

> --navail_bytes;

> }

>

> ret = b1 >> (8 - nbits_left);

> while (curr_size > nbits_left)

> {

> if (navail_bytes <= 0)

> {

>

> /* Out of bytes in current block, so read next block

> */

> pbytes = byte_buff;

> if ((navail_bytes = get_byte()) < 0)

> return(navail_bytes);

> else if (navail_bytes)

> {

> for (i = 0; i < navail_bytes; ++i)

> {

> if ((x = get_byte()) < 0)

> return(x);

> byte_buff[i] = x;

> }

> }

> }

> b1 = *pbytes++;

> ret |= b1 << nbits_left;

> nbits_left += 8;

> --navail_bytes;

> }

> nbits_left -= curr_size;

> ret &= code_mask[curr_size];

> return((short)(ret));

> }

>

> /* DECODE.C - An LZW decoder for GIF

> *

> * Copyright (C) 1987, by Steven A. Bennett

> *

> * Permission is given by the author to freely redistribute and include

> * this code in any program as long as this credit is given where due.

> *

> * In accordance with the above, I want to credit Steve Wilhite who wrote

> * the code which this is heavily inspired by...

> *

> * GIF and 'Graphics Interchange Format' are trademarks (tm) of

> * Compuserve, Incorporated, an H&R Block Company.

> *

> * Release Notes: This file contains a decoder routine for GIF images

> * which is similar, structurally, to the original routine by Steve Wilhite.

> * It is, however, somewhat noticably faster in most cases.

> *

> * short decode(linewidth)

> * short linewidth; * Pixels per line of image *

> *

> * - This function decodes an LZW image, according to the method used

> * in the GIF spec. Every *linewidth* "characters" (ie. pixels) decoded

> * will generate a call to out_line(), which is a user specific function

> * to display a line of pixels. The function gets it's codes from

> * get_next_code() which is responsible for reading blocks of data and

> * seperating them into the proper size codes. Finally, get_byte() is

> * the global routine to read the next byte from the GIF file.

> *

> * It is generally a good idea to have linewidth correspond to the actual

> * width of a line (as specified in the Image header) to make your own

> * code a bit simpler, but it isn't absolutely necessary.

> *

> * Returns: 0 if successful, else negative. (See ERRS.H)

> *

> */

>

> short decode(short linewidth)

> {

> register unsigned char *sp, *bufptr;

> unsigned char *buf;

> register short code, fc, oc, bufcnt;

> short c, size, ret;

>

> /* Initialize for decoding a new image...

> */

> if ((size = get_byte()) < 0)

> return(size);

> if (size < 2 || 9 < size)

> return(BAD_CODE_SIZE);

> init_exp(size);

>

> /* Initialize in case they forgot to put in a clear code.

> * (This shouldn't happen, but we'll try and decode it anyway...)

> */

> oc = fc = 0;

>

> /* Allocate space for the decode buffer

> */

> if ((buf = (unsigned char *)malloc(linewidth + 1)) == NULL)

> return(OUT_OF_MEMORY);

>

> /* Set up the stack pointer and decode buffer pointer

> */

> sp = stack;

> bufptr = buf;

> bufcnt = linewidth;

>

> /* This is the main loop. For each code we get we pass through the

> * linked list of prefix codes, pushing the corresponding "character" for

> * each code onto the stack. When the list reaches a single "character"

> * we push that on the stack too, and then start unstacking each

> * character for output in the correct order. Special handling is

> * included for the clear code, and the whole thing ends when we get

> * an ending code.

> */

> while ((c = get_next_code()) != ending)

> {

>

> /* If we had a file error, return without completing the decode

> */

> if (c < 0)

> {

> free(buf);

> return(0);

> }

>

> /* If the code is a clear code, reinitialize all necessary items.

> */

> if (c == clear)

> {

> curr_size = size + 1;

> slot = newcodes;

> top_slot = 1 << curr_size;

>

> /* Continue reading codes until we get a non-clear code

> * (Another unlikely, but possible case...)

> */

> while ((c = get_next_code()) == clear)

> ;

>

> /* If we get an ending code immediately after a clear code

> * (Yet another unlikely case), then break out of the loop.

> */

> if (c == ending)

> break;

>

> /* Finally, if the code is beyond the range of already set codes,

> * (This one had better NOT happen... I have no idea what will

> * result from this, but I doubt it will look good...) then set it

> * to color zero.

> */

> if (c >= slot)

> c = 0;

>

> oc = fc = c;

>

> /* And let us not forget to put the char into the buffer... And

> * if, on the off chance, we were exactly one pixel from the end

> * of the line, we have to send the buffer to the out_line()

> * routine...

> */

> *bufptr++ = c;

> if (--bufcnt == 0)

> {

> if ((ret = out_line(buf, linewidth)) < 0)

> {

> free(buf);

> return(ret);

> }

> bufptr = buf;

> bufcnt = linewidth;

> }

> }

> else

> {

>

> /* In this case, it's not a clear code or an ending code, so

> * it must be a code code... So we can now decode the code into

> * a stack of character codes. (Clear as mud, right?)

> */

> code = c;

>

> /* Here we go again with one of those off chances... If, on the

> * off chance, the code we got is beyond the range of those already

> * set up (Another thing which had better NOT happen...) we trick

> * the decoder into thinking it actually got the last code read.

> * (Hmmn... I'm not sure why this works... But it does...)

> */

> if (code >= slot)

> {

> if (code > slot)

> ++bad_code_count;

> code = oc;

> *sp++ = fc;

> }

>

> /* Here we scan back along the linked list of prefixes, pushing

> * helpless characters (ie. suffixes) onto the stack as we do so.

> */

> while (code >= newcodes)

> {

> *sp++ = suffix[code];

> code = prefix[code];

> }

>

> /* Push the last character on the stack, and set up the new

> * prefix and suffix, and if the required slot number is greater

> * than that allowed by the current bit size, increase the bit

> * size. (NOTE - If we are all full, we *don't* save the new

> * suffix and prefix... I'm not certain if this is correct...

> * it might be more proper to overwrite the last code...

> */

> *sp++ = code;

> if (slot < top_slot)

> {

> suffix[slot] = fc = code;

> prefix[slot++] = oc;

> oc = c;

> }

> if (slot >= top_slot)

> if (curr_size < 12)

> {

> top_slot <<= 1;

> ++curr_size;

> }

>

> /* Now that we've pushed the decoded string (in reverse order)

> * onto the stack, lets pop it off and put it into our decode

> * buffer... And when the decode buffer is full, write another

> * line...

> */

> while (sp > stack)

> {

> *bufptr++ = *(--sp);

> if (--bufcnt == 0)

> {

> if ((ret = out_line(buf, linewidth)) < 0)

> {

> free(buf);

> return(ret);

> }

> bufptr = buf;

> bufcnt = linewidth;

> }

> }

> }

> }

> ret = 0;

> if (bufcnt != linewidth)

> ret = out_line(buf, (linewidth - bufcnt));

> free(buf);

> return(ret);

> }

>

>

> // this function is called just before program exits

> void cleanup(void){

> // free any allocated resources

> if(fp!=NULL)

> fclose(fp);

> if(buffer!=NULL)

> free(buffer);

> if(grgb!=NULL)

> free(grgb);

> if(lrgb!=NULL)

> free(lrgb);

> if(pixels!=NULL)

> free(pixels);

> }

>

> void main(int argc, char **argv){

> unsigned int gctsize=0, lctsize=0, mode;

> int i;

>

> // set bad codes encountered to zero

> bad_code_count=0;

>

> // set function to be called on exit

> if(atexit(cleanup))

> exit(0);

>

> // exit if no file given

> if (argc<2){

> printf("Usage: %s gif_file\n", argv[0]);

> exit(0);

> }

>

> // try to open file

> if((fp=fopen(argv[1], "rb"))==NULL){

> printf("Failed to open file.\n");

> exit(0);

> }

>

> // allocate buffers

> buffer=(unsigned char *)malloc(BSIZE);

> pixels=(unsigned char *)malloc(ISIZE);

> grgb =(unsigned char *)malloc(PSIZE);

> lrgb =(unsigned char *)malloc(PSIZE);

> if((grgb==NULL) || (lrgb==NULL) || (pixels==NULL) || (buffer==NULL)){

> printf("Not enough memory.\n");

> exit(0);

> }

>

> fread(buffer, 1, 6, fp);

> // test file for valid GIF signature

> if(memcmp(buffer, "GIF", 3)!=0){

> printf("Not a GIF file.\n");

> exit(0);

> }

> // test file for version number

> if((memcmp(buffer+3, "87a", 3)!=0) && (memcmp(buffer+3, "89a", 3)!=0)){

> printf("Unsuported GIF version. Hit a key to decode anyway.\n");

> getch();

> }

>

> // read logical screen descriptor

> fread(buffer, 1, 7, fp);

>

> // test for global color table presence

> if(*(buffer+4)&0x80){

> // compute global color table size

> gctsize=1<<((*(buffer+4)&0x07) + 1);

> // read global color table into buffer

> fread(grgb, 1, gctsize*3, fp);

> // adjust colors to crappy 6-bit PC-DAC values

> for(i=0; i<gctsize*3; i++)

> *(grgb+i)>>=2;

> }

> // get background color index

> background=*(buffer+5);

>

>

> // scan file for data blocks

> while((i=get_byte())>0) {

> // in end of GIF marker encountered then exit

> if(i==0x3b)

> exit(0);

> // test for extentions

> if(i==0x21){

> if( (i=get_byte()) < 0 )

> exit(0);

> // if graphic color extention present or

> // coment extention present or

> // plain text extention present or

> // application extention present then skip it

> if( (i==0x01) || (i==0xf9) || (i==0xfe) || (i==0xff)){

> while((i=get_byte())!=0){

> if(fread(buffer, 1, i, fp)!=i)

> exit(0);

> }

> }

> }

>

> // test for presence of image descriptor

> if(i==0x2c){

> // get image descriptor

> fread(buffer, 1, 9, fp);

> // interlaced flag is set or cleared accordingly

> if(*(buffer+8)&0x40)

> group=1;

> realx=xsize=*(buffer+4) | (*(buffer+5)<<8);

> realy=ysize=*(buffer+6) | (*(buffer+7)<<8);

> // test for presence of local color table

> if(*(buffer+8)&0x80){

> // compute local color table size

> lctsize=1<<((*(buffer+8)&0x07) + 1);

> // read local color table into buffer

> fread(lrgb, 1, lctsize*3, fp);

> // adjust colors to crappy 6-bit PC-DAC values

> for(i=0; i<gctsize*3; i++)

> *(lrgb+i)>>=2;

> }

>

> // choose a video mode that will just fit the image

> if((xsize<=640) && (ysize<=480)){

> mode=0x101; // VESA 640 x 480 x 256

> xsize=640;

> ysize=480;

> } else if ((xsize<=800) && (ysize<=600)){

> mode=0x103; // VESA 800 x 600 x 256

> xsize=800;

> ysize=600;

> } else if ((xsize<=1024) && (ysize<=768)){

> mode=0x105; // VESA 1024 x 768 x 256

> xsize=1024;

> ysize=768;

> } else {

> mode=0x107; // VESA 1280 x 1024 x 256

> xsize=1280;

> ysize=1024;

> }

>

> piclen=(unsigned long)xsize*(unsigned long)ysize;

> // get video mode info through VESA call

> asm pusha

> asm mov ax, 0x4f01

> asm mov cx, mode

> asm les di, buffer

> asm int 0x10

> asm mov i, ax

> asm popa

>

> if(i!=0x004f){

> printf("VESA video functions not available.\n");

> exit(0);

> }

> // if mode not supported, or not color, or not graphics then exit

> if((*buffer&0x19)!=0x19){

> printf("Required graphics mode is not available.\n");

> exit(0);

> }

>

> // if window does not exist or is not writable exit

> if((*(buffer+2)&0x05)!=0x05) {

> printf("Cannot access video RAM.\n");

> exit(0);

> }

>

> // calculate window granularity

> granularity=(*(buffer+4) | (*(buffer+5)<<8))<<10;

> // calculate pointer to video RAM start

> vid=(unsigned char *)MK_FP((*(buffer+8) | (*(buffer+9)<<8)), 0);

>

> // set VESA video mode

> asm pusha

> asm mov ax, 0x4f02

> asm mov bx, mode

> asm int 0x10

> asm popa

>

> // set color table if present

> if(lctsize){

> // scope of local color table is local so once used it's gone

> lctsize=0;

> asm pusha

> asm mov ax, 0x1012

> asm mov bx, 0x0000

> asm mov cx, 0x0100

> asm les dx, lrgb

> asm int 0x10

> asm popa

> } else if(gctsize){

> // if no local color table then set global color table if present

> asm pusha

> asm mov ax, 0x1012

> asm mov bx, 0x0000

> asm mov cx, 0x0100

> asm les dx, grgb

> asm int 0x10

> asm pop es

> asm popa

> }

>

> // decode and display graphic

> decode(realx);

> // wait for key press

> getch();

>

> // set default text mode

> asm mov ax, 0x0003

> asm int 0x10

> }

> }

>

> // exit to dos

> exit(0);

> }

>

> -------------- chop here -------------------

>

> --

> +-----------------------------+-----------------------------------------------+

> | Alex Ivopol | If you love something set it free. If it |

> | cyborg@... | doesn't come back, hunt it down and kill it. |

> +-----------------------------+-----------------------------------------------+







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1dP9txL

View all the progranning help forums at:

http://ift.tt/1dP9txN

Monday, January 13, 2014

STL map to STL vector

Newsgroup: comp.lang.c++

Subject: STL map to STL vector

From: mrc2323@...

Date: Mon, 13 Jan 2014 17:06:47 -0700



Is it possible to simply (single statement) move the data from one

container type (the TeamMap, below) to a different type of container

(the TeamVector, below)? My data resides in the map object, but since I

have to occasionally display the data in different orders (e.g.

teamName, teamTypeCode), I must copy the data to a vector and sort it

before producing my listings.

I know that I can copy the individual objects from the map to the

vector one-at-a-time, but I'm hoping that there's a technique that will

do it simply and quickly. Any thoughts? TIA





typedef map<char, int> ShirtStats;

struct TeamData

{

bool isAdded; // Added to container data

bool isValidTeam; // really is a team

char teamTypeCode; // Team type Code

int teamMembers1; // Count of Team Members-1

int teamMembers2; // Count of Team Members-2

int genderCounts[NMAXEVT][2]; // counts of Gender by Event

int shirtTotalMatrix[5][8];

string teamCode; // Team's Code (strTId)

string teamName; // Team's Name

ShirtStats shirtStats;

} extern teamWork;

typedef map<string, TeamData> TeamMap;

TeamMap::iterator tIter;

ShirtStats::iterator ssIter;

TeamMap teamMap;

typedef vector<TeamData> TeamVector;

typedef TeamVector::iterator TeamIter;

TeamVector teamVect;

TeamIter tvIter;



---

This email is free from viruses and malware because avast! Antivirus protection is active.

http://www.avast.com









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?171704-STL-map-to-STL-vector&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

problem with iterator (map iterator)

Newsgroup: comp.lang.c++

Subject: problem with iterator (map iterator)

From: Jim Anderson <jjanderson52000@...>

Date: Fri, 10 Jan 2014 08:52:20 -0500



I'm writing a small program that will use a map (i.e. map<string,int>).

it has been a while since I have written in c++, so I found an example

on the internet and modified it for my own use. But when I try to

compile my program, I get a compile error.



The code looks ok to me, so I did a search on the internet to see if

others had the same problem. I found 3 or 4 examples, but the solutions

were all related to using an iterator, when infact a const_iterator

should be used. That is not the cause of my problem, as near as I can tell.



I have reduced my code to a simple example:



1

2 #include <iostream>

3 #include <map>

4 #include <string>

5

6 using namespace std;

7

8 int main()

9 {

10 map<string, int> totals;

11

12 totals.insert(std::pair<string,int>("NJ",10));

13 totals.insert(std::pair<string,int>("NY",20));

14 totals.insert(std::pair<string,int>("PA",30));

15 totals.insert(std::pair<string,int>("CT",40));

16

17 map<int,string>::iterator iter;

18 for(iter = totals.begin(); iter != totals.end(); ++iter) {

19 cout << (*iter).first << ": " << (*iter).second << endl;

20 }

21 }





I'm using the GNU compiler g++ version 4.4.5 on crunchbang linux. The

compile error messages are:



1 g++ -g -Wall -I/home/jja/bfs/include -DLINUX -c problem.cc

2 problem.cc: In function ?int main()?:

3 problem.cc:18: error: no match for ?operator=? in ?iter =

totals.std::map<_Key, _Tp, _Compare, _Alloc>::begin [ with _Key =

std::basic_string<char, std::char_traits<char>, std::allocator<char> >,

_Tp = int, _Compare = std:: less<std::basic_string<char,

std::char_traits<char>, std::allocator<char> > >, _Alloc =

std::allocator<std::pai r<const std::basic_string<char,

std::char_traits<char>, std::allocator<char> >, int> >]()?

4 /usr/include/c++/4.4/bits/stl_tree.h:154: note: candidates are:

std::_Rb_tree_iterator<std::pair<const int, std ::basic_string<char,

std::char_traits<char>, std::allocator<char> > > >&

std::_Rb_tree_iterator<std::pair<const int, std::basic_string<char,

std::char_traits<char>, std::allocator<char> > > >::operator=(const

std::_Rb_tree _iterator<std::pair<const int, std::basic_string<char,

std::char_traits<char>, std::allocator<char> > > >&)

5 problem.cc:18: error: no match for ?operator!=? in ?iter !=

totals.std::map<_Key, _Tp, _Compare, _Alloc>::end [ with _Key =

std::basic_string<char, std::char_traits<char>, std::allocator<char> >,

_Tp = int, _Compare = std:: less<std::basic_string<char,

std::char_traits<char>, std::allocator<char> > >, _Alloc =

std::allocator<std::pai r<const std::basic_string<char,

std::char_traits<char>, std::allocator<char> >, int> >]()?

6 /usr/include/c++/4.4/bits/stl_tree.h:216: note: candidates are:

bool std::_Rb_tree_iterator<_Tp>::operator!=(co nst

std::_Rb_tree_iterator<_Tp>&) const [with _Tp = std::pair<const int,

std::basic_string<char, std::char_trai ts<char>, std::allocator<char>

> >]

7 make: *** [problem.o] Error 1





Can anyone help explain the compile errors/



Jim Anderson







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?169041-problem-with-iterator-(map-iterator)&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Saturday, January 11, 2014

Sausages.

Newsgroup: comp.lang.c++

Subject: Sausages.

From: Mr Flibble <flibbleREMOVE_THIS@...>

Date: Sun, 29 Dec 2013 19:22:23 +0000



Sausages.



/Flibble







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?160958-Sausages&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Thursday, January 9, 2014

different rounding behavior with float and double

Newsgroup: comp.lang.c++

Subject: different rounding behavior with float and double

From: Raymond Li <faihk1@...>

Date: Thu, 09 Jan 2014 17:46:51 +0800



I have encountered a problem related to floating point rounding. I

googled a lot and there are many clear and helpful information. e.g.



http://www.learncpp.com/cpp-tutorial/25-floating-point-numbers/

http://support.microsoft.com/kb/125056/en-hk





Although the urls have explained the cause, I need to find a practical

way to solve a rounding problem. My program has calculated a weighted

accumulation as 3.5. When the figure is rounded to nearest number, it

became 3 (but I want it to round up to 4). I understood it would be due

to approximation value of 3.5 as 3.49999...



I found a simple fix by using float instead of double. I list the

program below and wish someone could explain why using double would

incur the rounding problem while float would not. In the code below,

fun1() use float and the calculation is 'correct'. In fun2(), it uses

double and the figure 3.5 is rounded as 3.



Raymond







//######################









#include <cmath>

#include <iostream>



//using namespace std;



using std::cout;

using std::endl;

int fun1();

int fun2();



int main(int argc, char ** argv)

{

fun1();

fun2();

return 0;

}







int fun1()

{



float weighted=10.0;

float average=100.0;

float z[]=

{

4.0,

4.0,

4.0,

4.0,

4.0,

3.0,

3.0,

3.0,

2.0,

4.0

};



float total=0.0;



int i=0;

for (i=0;i<10;i++)

{

float item=z[i]*weighted/average;

total=total+item;

cout << i << " accumulate is " << total << endl;

// NSLog(@... is %f, total is %f", i, z[i], total);

}



float answer=round(total);

// NSLog(@... is %f", answer);

cout << "rounded is " << answer << endl;

return 0;

}





int fun2()

{



double weighted=10.0;

double average=100.0;

double z[]=

{

4.0,

4.0,

4.0,

4.0,

4.0,

3.0,

3.0,

3.0,

2.0,

4.0

};



double total=0.0;



int i=0;

for (i=0;i<10;i++)

{

double item=z[i]*weighted/average;

total=total+item;

cout << i << " accumulate is " << total << endl;

// NSLog(@... is %f, total is %f", i, z[i], total);

}



double answer=round(total);

// NSLog(@... is %f", answer);

cout << "rounded is " << answer << endl;

return 0;

}



0 accumulate is 0.4

1 accumulate is 0.8

2 accumulate is 1.2

3 accumulate is 1.6

4 accumulate is 2

5 accumulate is 2.3

6 accumulate is 2.6

7 accumulate is 2.9

8 accumulate is 3.1

9 accumulate is 3.5

rounded is 4

***(above is the version using float, 3.5 is rounded as 4) ***



0 accumulate is 0.4

1 accumulate is 0.8

2 accumulate is 1.2

3 accumulate is 1.6

4 accumulate is 2

5 accumulate is 2.3

6 accumulate is 2.6

7 accumulate is 2.9

8 accumulate is 3.1

9 accumulate is 3.5

rounded is 3



***(this version use double, 3.5 is rounded as 3) ***





--- news://freenews.netfront.net/ - complaints: news@... ---







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?167977-different-rounding-behavior-with-float-and-double&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Sunday, January 5, 2014

C++ standards committee looking at adding Cairo to the C++ standard

Newsgroup: comp.lang.c++

Subject: C++ standards committee looking at adding Cairo to the C++ standard

From: Rui Maciel <rui.maciel@...>

Date: Sun, 05 Jan 2014 15:20:24 +0000



It appears that Herb Sutter wants to add a 2D drawing library to the C++ standard, and he is

looking at libCairo as a base for this library.



The link to the Cairo's mailing list:

http://lists.cairographics.org/archives/cairo/2013-December/024858.html





What are your thoughts on this?





Rui Maciel







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?164796-C-standards-committee-looking-at-adding-Cairo-to-the-C-standard&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

C++/QT/ARM Processors Cross-compiling/Programming Problem

Newsgroup: comp.lang.c++

Subject: C++/QT/ARM Processors Cross-compiling/Programming Problem

From: Saeed Amrollahi <amrollahi.saeed@...>

Date: Sat, 4 Jan 2014 01:55:07 -0800 (PST)



dear all {C++|QT|Embedded Systems} developers

Hello

before anything, Happy new year.

In advance please accept my apologizes, if my question(s) are somehow off-topic.

If so, please give me some advice to choose appropriate discussion groups.



Recently, I'm involved in a QT/ARM Processor software development project.

The general components of the project is:

Processor: Mini440 FriendlyARM (400 MHz Samsung S3C2440 ARM926T),

www.friendlyarm.net

www.arm9.net

OS: Linux (Kernel version 2.6.32)

Programming Language: C++ (GCC/g++)

GUI Framework: QT

The main purpose of the project is to develop a GUI for the

embedded handheld device, using QT/Embedded Linux.



The output of command uname -a on host computer (development machine) is:

$ uname -a

Linux scorpion 3.5.0-39-generic #60~precise1-Ubuntu SMP Wed Aug 14 15:38:41 UTC 2013

x86_64 x86_64 x86_64 GNU/Linux

The output of command uname -a on embedded ARM-based device is:

Liunx FriendlyARM 2.6.32-FriendlyARM #5 Wed Jun 6 15:50:50

HKT 2012 armv4tl unknown.

My first question is:

Q. Is it important to host and target computers have the same architecture,

I mean both should be 32-bits (x86 or i586/i686) or both should be 64-bits (x86_64)?



I did the following steps:

1. I wrote a simple GUI using QT Creator (2.7.0) based on QT Designer (5.0.2)

on a desktop Linux machine (host computer)

2. Based on knowledge, I gained in last two months from books and Intenet about Cross-compiling,

and tool-chain and other many many related concepts, I found I have to install another

software from Trolltech called Qtopia, the Embedded version of QT. I tries

to install the latest version of Qtopia called qtopia-core-opensource-src-4.3.5

at this point I had a lot of problems at configuration, building and making the

software. One problem is g++ on host is 4.8.1 (very new), but the Qtopia

is for about 7 years ago. When I tries to build the Qtopia from source

the g++ compiler issues several C++ errors, for example:

error: 'ptrdiff_t' does not name a type

error: 'append' was not declared in this scope, and no declaration, where found

by argument-dependent lookup

Of course, I solved these problems, but it's obvious g++ issues these errors

because Qtopia was written using C++98, but g++ 4.8.1 is based on C++11

my questions are:

Q. Is it important to use which version of GCC with Qtopia?

another thing is which version of QT/Embedded should be used?

Q. Do I have to use the old versions of QT/Embedded like Qtopia or

I can use the newer versions like qt-everywhere-opensource-src-4.8.4?



another problem is about kernel version: is it important

Q. Is it important to host and target computers have the same kernel number (x.y.z)?



As you can see, I lost in details of cross-compiling and porting written software

from host to embedded device. I almost have no problem in using QT and writing C++ in desktop version.

At last, I appreciate you to give a your general but practical guideline/tips

to cross-compiling from x86 GCC to FreindlyARM platform.



Please shed some light.

TIA



-- Saeed Amrollahi Boyouki







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?164157-C-QT-ARM-Processors-Cross-compiling-Programming-Problem&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Saturday, January 4, 2014

Practice of basic concepts

Newsgroup: comp.lang.c++

Subject: Practice of basic concepts

From: TwistedRoar <viniss17@...>

Date: Wed, 1 Jan 2014 10:12:12 -0800 (PST)



I'm quite new to C++, I started learning it a few days ago and, even though I do have some good studying material with me, I feel I lack a lot of practice...is there any online tutorial with activities or anything like that you could recommend me?







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?162511-Practice-of-basic-concepts&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Friendly GUI for windows building?

Newsgroup: comp.lang.c++

Subject: Friendly GUI for windows building?

From: Francois Guillet <guillet.francois@...>

Date: Sat, 04 Jan 2014 11:51:21 +0100



Hi



Creating many windows and controls is very tedious when the parameters

of the CreateWindowEx function have to be set manually.



I'm looking for a tool able to build code automatically from drag and

drop of objects (buttons, check boxes, edit controls...) onto a first

empty window, and allowing repositionning, sizing, property settings...



This was provided in environments like C++ builder, but I'm searching

for a more light tool that would generate simple cpp and h files to

include in my project and that wouldn't need an obscure and heavy

library (I'm using codeblock/gcc/mingw).



Some advises?



Thanks







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?164222-Friendly-GUI-for-windows-building&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Behavior of the local class

Newsgroup: comp.lang.c++

Subject: Behavior of the local class

From: somenath <somenathpal@...>

Date: Thu, 2 Jan 2014 01:22:47 -0800 (PST)



I am not able to understand why the following program does not compile.

#include<iostream>

using namespace std;



template <class T >

void Fun(T t)

{

static int i = t;



class Test {

public:

Test( int t1) {

cout<<"Value = "<<i<<endl;

}

};

Test tt(t);



}





int main(void)

{

Fun<int >(5);

return 0;



}

Whenever I try to compile the program I get the following error

g++ LocalClass.cpp

/tmp/ccfEKvyT.o:LocalClass.cpp:(.text+0x2b): undefined reference to `i'

collect2: ld returned 1 exit status





But I am aware that local class can access the static local variable of enclosing function. The following program proves that as well.



#include<iostream>

using namespace std;



void Fun(int t)

{

static int i=t;



class Test {

public:

Test( int t1) {

cout<<"Value = "<<i<<endl;

}

};

Test tt(t);



}



int main(void)

{

Fun(5);

return 0;



}

This code compile fine. Then what is going wrong with template version of the program?







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?162857-Behavior-of-the-local-class&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Friday, January 3, 2014

Why does this template code compile?

Newsgroup: comp.lang.c++

Subject: Why does this template code compile?

From: Peter <pilarp@...>

Date: Fri, 3 Jan 2014 16:25:54 -0800 (PST)



In "C++ Templates The Complete Guide" book by Vandevoorde

and Josuttis I found the following template definition

near the end of chapter 8.2 ("Template Arguments"):



template<template<typename T, T*> class Buf>

class Lexer

{

static char storage[5];

Buf<char, &Lexer<Buf>::storage> buf;

};



Buf is a template template argument whose template

arguments are: type parameter T and unnamed non-type

parameter - a pointer to T. In the definition of Lexer,

Buf is instantiated so that T = char and second argument

(of type T*) is &Lexer<Buf>::storage, but why is this

second substitution correct?

How does &Lexer<Buf>::storage resolve to char*?



Here's my reasoning.



Lex<Buf>::storage is of type char[5],

&Lex<Buf>::storage is of type char(*)[5].



If we had:



Buf<char, Lexer<Buf>::storage> buf;



instead of:



Buf<char, &Lexer<Buf>::storage> buf;



in the definition of Lexer template then

Lexer<Buf>::storage would decay to char*, but why

can the template be instantiated with

&Lexer<Buf>::storage as well? I tested both definitions

here:



http://www.compileonline.com/compile_cpp11_online.php



and they both compile.



However, if I try to instantiate Lexer with

&Lexer<Buf>::storage as second argument to Buf, I get

a compilation error as expected. Here's a complete example:





template<template<typename T, T*> class Buf>

class Lexer

{

static char storage[5];

Buf<char, &Lexer<Buf>::storage> buf;

};



template<typename T, T*>

class Foo

{

};



int main()

{

Lexer<Foo> lex;

return 0;

}



Now:



1) if I try to compile the above I get the following error:



main.cpp: In instantiation of 'class Lexer<Foo>':

main.cpp:15:15: required from here

main.cpp:5:37: error: could not convert template argument

'& Lexer<Foo>::storage' to 'char*'



2) if I change "&Lexer<Buf>::storage" to

"Lexer<Buf>::storage" the code compiles



3) if I comment out the instantiation of Lexer from main()

the code compiles with either &Lexer<Buf>::storage or

Lexer<Buf>::storage as second argument to Buf.



Can you explain what happens here and why Buf template can

be instantiated with either of the two arguments?







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?164028-Why-does-this-template-code-compile&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums