Search Results

Search found 2613 results on 105 pages for 'undefined'.

Page 3/105 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • got undefined variable in php code

    - by Newbie New
    I got a error message when I run my php however the result is come out this is my code function cart() { foreach($_SESSION as $name => $value) { if ($value>0) { if (substr($name, 0, 5) == 'cart_'){ $id = substr($name, 5, (strlen($name)-5)); $get = mysql_query('SELECT id, name, price FROM products WHERE id=' .mysql_real_escape_string((int)$id)); while ($get_row = mysql_fetch_assoc($get)){ $sub = $get_row['price'] * $value; echo $get_row['name'].' x '.$value.' @ &pound'.number_format($get_row['price'], 2).' = &pound'.number_format($sub, 2).' <a href="cart.php?remove='.$id.'">[-]</a> <a href="cart.php?add='.$id.'">[+]</a> <a href="cart.php?delete='.$id.'">[Delete]</a><br />' ; } } $total += $sub; } } echo $total; } ?> I got a error message Notice: Undefined variable: total in C:\xampp\htdocs\shoppingcart\cart.php on line 54 which line 54 is echo $total; what's wrong with my code?? I think I have defined the code in $total += $sub; thanks for helping me :)

    Read the article

  • Undefined index: email in C:\wamp\www\emailvalidate.php on line 4

    - by klari
    I am new to Ajax. In my Ajax I get the following error message : Notice: Undefined index: address in C:\wamp\www\test\sample.php on line 11 I googled but I didn't get a solution for my specified issue. Here is what I did. HTML Form with Ajax (test1.php) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script> function loadXMLDoc() { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("mydiv").innerHTML=xmlhttp.responseText; } } xmlhttp.open("POST","test2.php",true); xmlhttp.send(); } </script> </head> <body> <form id="form1" name="form1" method="post" action="sample.php"> <p> <label for="mail"></label> <input type="text" name="mail" id="mail" onblur="loadXMLDoc()" /> <input type="submit" name="submit" id="submit" value="Submit" /> </p> <p><div id = 'mydiv'></div></p> </form> </body> </html> test2.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php echo "Your Address is ".$_POST['address']; ?> </body> </html> I am sure it is very simple issue but I don't know how to solve it. Any help ?

    Read the article

  • Make file Linking issue Undefined symbols for architecture x86_64

    - by user1035839
    I am working on getting a few files to link together using my make file and c++ and am getting the following error when running make. g++ -bind_at_load `pkg-config --cflags opencv` -c -o compute_gist.o compute_gist.cpp g++ -bind_at_load `pkg-config --cflags opencv` -c -o gist.o gist.cpp g++ -bind_at_load `pkg-config --cflags opencv` -c -o standalone_image.o standalone_image.cpp g++ -bind_at_load `pkg-config --cflags opencv` -c -o IplImageConverter.o IplImageConverter.cpp g++ -bind_at_load `pkg-config --cflags opencv` -c -o GistCalculator.o GistCalculator.cpp g++ -bind_at_load `pkg-config --cflags opencv` `pkg-config --libs opencv` compute_gist.o gist.o standalone_image.o IplImageConverter.o GistCalculator.o -o rungist Undefined symbols for architecture x86_64: "color_gist_scaletab(color_image_t*, int, int, int const*)", referenced from: _main in compute_gist.o ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status make: *** [rungist] Error 1 My makefile is as follows (Note, I don't need opencv bindings yet, but will be coding in opencv later. CXX = g++ CXXFLAGS = -bind_at_load `pkg-config --cflags opencv` LFLAGS = `pkg-config --libs opencv` SRC = \ compute_gist.cpp \ gist.cpp \ standalone_image.cpp \ IplImageConverter.cpp \ GistCalculator.cpp OBJS = $(SRC:.cpp=.o) rungist: $(OBJS) $(CXX) $(CXXFLAGS) $(LFLAGS) $(OBJS) -o $@ all: rungist clean: rm -rf $(OBJS) rungist The method header is located in gist.h float *color_gist_scaletab(color_image_t *src, int nblocks, int n_scale, const int *n_orientations); And the method is defined in gist.cpp float *color_gist_scaletab(color_image_t *src, int w, int n_scale, const int *n_orientation) { And finally the compute_gist.cpp (main file) #include <stdio.h> #include <stdlib.h> #include <string.h> #include "gist.h" static color_image_t *load_ppm(const char *fname) { FILE *f=fopen(fname,"r"); if(!f) { perror("could not open infile"); exit(1); } int width,height,maxval; if(fscanf(f,"P6 %d %d %d",&width,&height,&maxval)!=3 || maxval!=255) { fprintf(stderr,"Error: input not a raw PPM with maxval 255\n"); exit(1); } fgetc(f); /* eat the newline */ color_image_t *im=color_image_new(width,height); int i; for(i=0;i<width*height;i++) { im->c1[i]=fgetc(f); im->c2[i]=fgetc(f); im->c3[i]=fgetc(f); } fclose(f); return im; } static void usage(void) { fprintf(stderr,"compute_gist options... [infilename]\n" "infile is a PPM raw file\n" "options:\n" "[-nblocks nb] use a grid of nb*nb cells (default 4)\n" "[-orientationsPerScale o_1,..,o_n] use n scales and compute o_i orientations for scale i\n" ); exit(1); } int main(int argc,char **args) { const char *infilename="/dev/stdin"; int nblocks=4; int n_scale=3; int orientations_per_scale[50]={8,8,4}; while(*++args) { const char *a=*args; if(!strcmp(a,"-h")) usage(); else if(!strcmp(a,"-nblocks")) { if(!sscanf(*++args,"%d",&nblocks)) { fprintf(stderr,"could not parse %s argument",a); usage(); } } else if(!strcmp(a,"-orientationsPerScale")) { char *c; n_scale=0; for(c=strtok(*++args,",");c;c=strtok(NULL,",")) { if(!sscanf(c,"%d",&orientations_per_scale[n_scale++])) { fprintf(stderr,"could not parse %s argument",a); usage(); } } } else { infilename=a; } } color_image_t *im=load_ppm(infilename); //Here's the method call -> :( float *desc=color_gist_scaletab(im,nblocks,n_scale,orientations_per_scale); int i; int descsize=0; //compute descriptor size for(i=0;i<n_scale;i++) descsize+=nblocks*nblocks*orientations_per_scale[i]; descsize*=3; // color //print descriptor for(i=0;i<descsize;i++) printf("%.4f ",desc[i]); printf("\n"); free(desc); color_image_delete(im); return 0; } Any help would be greatly appreciated. I hope this is enough info. Let me know if I need to add more.

    Read the article

  • Strange (Undefined?) Behavior of Free in C

    - by Chris Cirefice
    This is really strange... and I can't debug it (tried for about two hours, debugger starts going haywire after a while...). Anyway, I'm trying to do something really simple: Free an array of strings. The array is in the form: char **myStrings. The array elements are initialized as: myString[index] = malloc(strlen(word)); myString[index] = word; and I'm calling a function like this: free_memory(myStrings, size); where size is the length of the array (I know this is not the problem, I tested it extensively and everything except this function is working). free_memory looks like this: void free_memory(char **list, int size) { for (int i = 0; i < size; i ++) { free(list[i]); } free(list); } Now here comes the weird part. if (size> strlen(list[i])) then the program crashes. For example, imagine that I have a list of strings that looks something like this: myStrings[0] = "Some"; myStrings[1] = "random"; myStrings[2] = "strings"; And thus the length of this array is 3. If I pass this to my free_memory function, strlen(myStrings[0]) > 3 (4 3), and the program crashes. However, if I change myStrings[0] to be "So" instead, then strlen(myStrings[0]) < 3 (2 < 3) and the program does not crash. So it seems to me that free(list[i]) is actually going through the char[] that is at that location and trying to free each character, which I imagine is undefined behavior. The only reason I say this is because I can play around with the size of the first element of myStrings and make the program crash whenever I feel like it, so I'm assuming that this is the problem area. Note: I did try to debug this by stepping through the function that calls free_memory, noting any weird values and such, but the moment I step into the free_memory function, the debugger crashes, so I'm not really sure what is going on. Nothing is out of the ordinary until I enter the function, then the world explodes. Another note: I also posted the shortened version of the source for this program (not too long; Pastebin) here. I am compiling on MinGW with the c99 flag on. PS - I just thought of this. I am indeed passing numUniqueWords to the free function, and I know that this does not actually free the entire piece of memory that I allocated. I've called it both ways, that's not the issue. And I left it how I did because that is the way that I will be calling it after I get it to work in the first place, I need to revise some of my logic in that function. Source, as per request (on-site): #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> #include "words.h" int getNumUniqueWords(char text[], int size); int main(int argc, char* argv[]) { setvbuf(stdout, NULL, 4, _IONBF); // For Eclipse... stupid bug. --> does NOT affect the program, just the output to console! int nbr_words; char text[] = "Some - \"text, a stdin\". We'll have! also repeat? We'll also have a repeat!"; int length = sizeof(text); nbr_words = getNumUniqueWords(text, length); return 0; } void free_memory(char **list, int size) { for (int i = 0; i < size; i ++) { // You can see that printing the values is fine, as long as free is not called. // When free is called, the program will crash if (size > strlen(list[i])) //printf("Wanna free value %d w/len of %d: %s\n", i, strlen(list[i]), list[i]); free(list[i]); } free(list); } int getNumUniqueWords(char text[], int length) { int numTotalWords = 0; char *word; printf("Length: %d characters\n", length); char totalWords[length]; strcpy(totalWords, text); word = strtok(totalWords, " ,.-!?()\"0123456789"); while (word != NULL) { numTotalWords ++; printf("%s\n", word); word = strtok(NULL, " ,.-!?()\"0123456789"); } printf("Looks like we counted %d total words\n\n", numTotalWords); char *uniqueWords[numTotalWords]; char *tempWord; int wordAlreadyExists = 0; int numUniqueWords = 0; char totalWordsCopy[length]; strcpy(totalWordsCopy, text); for (int i = 0; i < numTotalWords; i++) { uniqueWords[i] = NULL; } // Tokenize until all the text is consumed. word = strtok(totalWordsCopy, " ,.-!?()\"0123456789"); while (word != NULL) { // Look through the word list for the current token. for (int j = 0; j < numTotalWords; j ++) { // Just for clarity, no real meaning. tempWord = uniqueWords[j]; // The word list is either empty or the current token is not in the list. if (tempWord == NULL) { break; } //printf("Comparing (%s) with (%s)\n", tempWord, word); // If the current token is the same as the current element in the word list, mark and break if (strcmp(tempWord, word) == 0) { printf("\nDuplicate: (%s)\n\n", word); wordAlreadyExists = 1; break; } } // Word does not exist, add it to the array. if (!wordAlreadyExists) { uniqueWords[numUniqueWords] = malloc(strlen(word)); uniqueWords[numUniqueWords] = word; numUniqueWords ++; printf("Unique: %s\n", word); } // Reset flags and continue. wordAlreadyExists = 0; word = strtok(NULL, " ,.-!?()\"0123456789"); } // Print out the array just for funsies - make sure it's working properly. for (int x = 0; x <numUniqueWords; x++) { printf("Unique list %d: %s\n", x, uniqueWords[x]); } printf("\nNumber of unique words: %d\n\n", numUniqueWords); // Right below is where things start to suck. free_memory(uniqueWords, numUniqueWords); return numUniqueWords; }

    Read the article

  • PHP use of undefined constant error

    - by user272899
    Using a great script to grab details from imdb, I would like to thank Fabian Beiner. Just one error i have encountered with it is: Use of undefined constant sys_get_temp_dir assumed 'sys_get_temp_dir' in '/path/to/directory' on line 49 This is the complete script <?php /** * IMDB PHP Parser * * This class can be used to retrieve data from IMDB.com with PHP. This script will fail once in * a while, when IMDB changes *anything* on their HTML. Guys, it's time to provide an API! * * @link http://fabian-beiner.de * @copyright 2010 Fabian Beiner * @author Fabian Beiner (mail [AT] fabian-beiner [DOT] de) * @license MIT License * * @version 4.1 (February 1st, 2010) * */ class IMDB { private $_sHeader = null; private $_sSource = null; private $_sUrl = null; private $_sId = null; public $_bFound = false; private $_oCookie = '/tmp/imdb-grabber-fb.tmp'; const IMDB_CAST = '#<a href="/name/(\w+)/" onclick="\(new Image\(\)\)\.src=\'/rg/castlist/position-(\d|\d\d)/images/b\.gif\?link=/name/(\w+)/\';">(.*)</a>#Ui'; const IMDB_COUNTRY = '#<a href="/Sections/Countries/(\w+)/">#Ui'; const IMDB_DIRECTOR = '#<a href="/name/(\w+)/" onclick="\(new Image\(\)\)\.src=\'/rg/directorlist/position-(\d|\d\d)/images/b.gif\?link=name/(\w+)/\';">(.*)</a><br/>#Ui'; const IMDB_GENRE = '#<a href="/Sections/Genres/(\w+|\w+\-\w+)/">(\w+|\w+\-\w+)</a>#Ui'; const IMDB_MPAA = '#<h5><a href="/mpaa">MPAA</a>:</h5>\s*<div class="info-content">\s*(.*)\s*</div>#Ui'; const IMDB_PLOT = '#<h5>Plot:</h5>\s*<div class="info-content">\s*(.*)\s*<a#Ui'; const IMDB_POSTER = '#<a name="poster" href="(.*)" title="(.*)"><img border="0" alt="(.*)" title="(.*)" src="(.*)" /></a>#Ui'; const IMDB_RATING = '#<b>(\d\.\d/10)</b>#Ui'; const IMDB_RELEASE_DATE = '#<h5>Release Date:</h5>\s*\s*<div class="info-content">\s*(.*) \((.*)\)#Ui'; const IMDB_RUNTIME = '#<h5>Runtime:</h5>\s*<div class="info-content">\s*(.*)\s*</div>#Ui'; const IMDB_SEARCH = '#<b>Media from&nbsp;<a href="/title/tt(\d+)/"#i'; const IMDB_TAGLINE = '#<h5>Tagline:</h5>\s*<div class="info-content">\s*(.*)\s*</div>#Ui'; const IMDB_TITLE = '#<title>(.*) \((.*)\)</title>#Ui'; const IMDB_URL = '#http://(.*\.|.*)imdb.com/(t|T)itle(\?|/)(..\d+)#i'; const IMDB_VOTES = '#&nbsp;&nbsp;<a href="ratings" class="tn15more">(.*) votes</a>#Ui'; const IMDB_WRITER = '#<a href="/name/(\w+)/" onclick="\(new Image\(\)\)\.src=\'/rg/writerlist/position-(\d|\d\d)/images/b\.gif\?link=name/(\w+)/\';">(.*)</a>#Ui'; const IMDB_REDIRECT = '#Location: (.*)#'; /** * Public constructor. * * @param string $sSearch */ public function __construct($sSearch) { if (function_exists(sys_get_temp_dir)) { $this->_oCookie = tempnam(sys_get_temp_dir(), 'imdb'); } $sUrl = $this->findUrl($sSearch); if ($sUrl) { $bFetch = $this->fetchUrl($this->_sUrl); $this->_bFound = true; } } /** * Little REGEX helper. * * @param string $sRegex * @param string $sContent * @param int $iIndex; */ private function getMatch($sRegex, $sContent, $iIndex = 1) { preg_match($sRegex, $sContent, $aMatches); if ($iIndex > count($aMatches)) return; if ($iIndex == null) { return $aMatches; } return $aMatches[(int)$iIndex]; } /** * Little REGEX helper, I should find one that works for both... ;/ * * @param string $sRegex * @param int $iIndex; */ private function getMatches($sRegex, $iIndex = null) { preg_match_all($sRegex, $this->_sSource, $aMatches); if ((int)$iIndex) return $aMatches[$iIndex]; return $aMatches; } /** * Save an image. * * @param string $sUrl */ private function saveImage($sUrl) { $sUrl = trim($sUrl); $bolDir = false; if (!is_dir(getcwd() . '/posters')) { if (mkdir(getcwd() . '/posters', 0777)) { $bolDir = true; } } $sFilename = getcwd() . '/posters/' . preg_replace("#[^0-9]#", "", basename($sUrl)) . '.jpg'; if (file_exists($sFilename)) { return 'posters/' . basename($sFilename); } if (is_dir(getcwd() . '/posters') OR $bolDir) { if (function_exists('curl_init')) { $oCurl = curl_init($sUrl); curl_setopt_array($oCurl, array ( CURLOPT_VERBOSE => 0, CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_TIMEOUT => 5, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_REFERER => $sUrl, CURLOPT_BINARYTRANSFER => 1)); $sOutput = curl_exec($oCurl); curl_close($oCurl); $oFile = fopen($sFilename, 'x'); fwrite($oFile, $sOutput); fclose($oFile); return 'posters/' . basename($sFilename); } else { $oImg = imagecreatefromjpeg($sUrl); imagejpeg($oImg, $sFilename); return 'posters/' . basename($sFilename); } return false; } return false; } /** * Find a valid Url out of the passed argument. * * @param string $sSearch */ private function findUrl($sSearch) { $sSearch = trim($sSearch); if ($aUrl = $this->getMatch(self::IMDB_URL, $sSearch, 4)) { $this->_sId = 'tt' . preg_replace('[^0-9]', '', $aUrl); $this->_sUrl = 'http://www.imdb.com/title/' . $this->_sId .'/'; return true; } else { $sTemp = 'http://www.imdb.com/find?s=all&q=' . str_replace(' ', '+', $sSearch) . '&x=0&y=0'; $bFetch = $this->fetchUrl($sTemp); if( $this->isRedirect() ) { return true; } else if ($bFetch) { if ($strMatch = $this->getMatch(self::IMDB_SEARCH, $this->_sSource)) { $this->_sUrl = 'http://www.imdb.com/title/tt' . $strMatch . '/'; unset($this->_sSource); return true; } } } return false; } /** * Find if result is redirected directly to exact movie. */ private function isRedirect() { if ($strMatch = $this->getMatch(self::IMDB_REDIRECT, $this->_sHeader)) { $this->_sUrl = $strMatch; unset($this->_sSource); unset($this->_sHeader); return true; } return false; } /** * Fetch data from given Url. * Uses cURL if installed, otherwise falls back to file_get_contents. * * @param string $sUrl * @param int $iTimeout; */ private function fetchUrl($sUrl, $iTimeout = 15) { $sUrl = trim($sUrl); if (function_exists('curl_init')) { $oCurl = curl_init($sUrl); curl_setopt_array($oCurl, array ( CURLOPT_VERBOSE => 0, CURLOPT_HEADER => 1, CURLOPT_FRESH_CONNECT => true, CURLOPT_RETURNTRANSFER => 1, CURLOPT_TIMEOUT => (int)$iTimeout, CURLOPT_CONNECTTIMEOUT => (int)$iTimeout, CURLOPT_REFERER => $sUrl, CURLOPT_FOLLOWLOCATION => 0, CURLOPT_COOKIEFILE => $this->_oCookie, CURLOPT_COOKIEJAR => $this->_oCookie, CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6' )); $sOutput = curl_exec($oCurl); if ($sOutput === false) { return false; } $aInfo = curl_getinfo($oCurl); if ($aInfo['http_code'] != 200 && $aInfo['http_code'] != 302) { return false; } $sTmpHeader = strpos($sOutput, "\r\n\r\n"); $this->_sHeader = substr($sOutput, 0, $sTmpHeader); $this->_sSource = str_replace("\n", '', substr($sOutput, $sTmpHeader+1)); curl_close($oCurl); return true; } else { $sOutput = @file_get_contents($sUrl, 0); if (strpos($http_response_header[0], '200') === false){ return false; } $this->_sSource = str_replace("\n", '', (string)$sOutput); return true; } return false; } /** * Returns the cast. */ public function getCast($iOutput = null, $bMore = true) { if ($this->_sSource) { $sReturned = $this->getMatches(self::IMDB_CAST, 4); if (is_array($sReturned)) { if ($iOutput) { foreach ($sReturned as $i => $sName) { if ($i >= $iOutput) break; $sReturn[] = $sName; } return implode(' / ', $sReturn) . (($bMore) ? '&hellip;' : ''); } return implode(' / ', $sReturned); } return $sReturned; } return 'n/A'; } /** * Returns the cast as links. */ public function getCastAsUrl($iOutput = null, $bMore = true) { if ($this->_sSource) { $sReturned1 = $this->getMatches(self::IMDB_CAST, 4); $sReturned2 = $this->getMatches(self::IMDB_CAST, 3); if (is_array($sReturned1)) { if ($iOutput) { foreach ($sReturned1 as $i => $sName) { if ($i >= $iOutput) break; $aReturn[] = '<a href="http://www.imdb.com/name/' . $sReturned2[$i] . '/">' . $sName . '</a>';; } return implode(' / ', $aReturn) . (($bMore) ? '&hellip;' : ''); } return implode(' / ', $sReturned); } return '<a href="http://www.imdb.com/name/' . $sReturned2 . '/">' . $sReturned1 . '</a>';; } return 'n/A'; } /** * Returns the countr(y|ies). */ public function getCountry() { if ($this->_sSource) { $sReturned = $this->getMatches(self::IMDB_COUNTRY, 1); if (is_array($sReturned)) { return implode(' / ', $sReturned); } return $sReturned; } return 'n/A'; } /** * Returns the countr(y|ies) as link(s). */ public function getCountryAsUrl() { if ($this->_sSource) { $sReturned = $this->getMatches(self::IMDB_COUNTRY, 1); if (is_array($sReturned)) { foreach ($sReturned as $sCountry) { $aReturn[] = '<a href="http://www.imdb.com/Sections/Countries/' . $sCountry . '/">' . $sCountry . '</a>'; } return implode(' / ', $aReturn); } return '<a href="http://www.imdb.com/Sections/Countries/' . $sReturned . '/">' . $sReturned . '</a>'; } return 'n/A'; } /** * Returns the director(s). */ public function getDirector() { if ($this->_sSource) { $sReturned = $this->getMatches(self::IMDB_DIRECTOR, 4); if (is_array($sReturned)) { return implode(' / ', $sReturned); } return $sReturned; } return 'n/A'; } /** * Returns the director(s) as link(s). */ public function getDirectorAsUrl() { if ($this->_sSource) { $sReturned1 = $this->getMatches(self::IMDB_DIRECTOR, 4); $sReturned2 = $this->getMatches(self::IMDB_DIRECTOR, 1); if (is_array($sReturned1)) { foreach ($sReturned1 as $i => $sDirector) { $aReturn[] = '<a href="http://www.imdb.com/name/' . $sReturned2[$i] . '/">' . $sDirector . '</a>'; } return implode(' / ', $aReturn); } return '<a href="http://www.imdb.com/name/' . $sReturned2 . '/">' . $sReturned1 . '</a>'; } return 'n/A'; } /** * Returns the genre(s). */ public function getGenre() { if ($this->_sSource) { $sReturned = $this->getMatches(self::IMDB_GENRE, 1); if (is_array($sReturned)) { return implode(' / ', $sReturned); } return $sReturned; } return 'n/A'; } /** * Returns the genre(s) as link(s). */ public function getGenreAsUrl() { if ($this->_sSource) { $sReturned = $this->getMatches(self::IMDB_GENRE, 1); if (is_array($sReturned)) { foreach ($sReturned as $i => $sGenre) { $aReturn[] = '<a href="http://www.imdb.com/Sections/Genres/' . $sGenre . '/">' . $sGenre . '</a>'; } return implode(' / ', $aReturn); } return '<a href="http://www.imdb.com/Sections/Genres/' . $sReturned . '/">' . $sReturned . '</a>'; } return 'n/A'; } /** * Returns the mpaa. */ public function getMpaa() { if ($this->_sSource) { return implode('' , $this->getMatches(self::IMDB_MPAA, 1)); } return 'n/A'; } /** * Returns the plot. */ public function getPlot() { if ($this->_sSource) { return implode('' , $this->getMatches(self::IMDB_PLOT, 1)); } return 'n/A'; } /** * Download the poster, cache it and return the local path to the image. */ public function getPoster() { if ($this->_sSource) { if ($sPoster = $this->saveImage(implode("", $this->getMatches(self::IMDB_POSTER, 5)), 'poster.jpg')) { return $sPoster; } return implode('', $this->getMatches(self::IMDB_POSTER, 5)); } return 'n/A'; } /** * Returns the rating. */ public function getRating() { if ($this->_sSource) { return implode('', $this->getMatches(self::IMDB_RATING, 1)); } return 'n/A'; } /** * Returns the release date. */ public function getReleaseDate() { if ($this->_sSource) { return implode('', $this->getMatches(self::IMDB_RELEASE_DATE, 1)); } return 'n/A'; } /** * Returns the runtime of the current movie. */ public function getRuntime() { if ($this->_sSource) { return implode('', $this->getMatches(self::IMDB_RUNTIME, 1)); } return 'n/A'; } /** * Returns the tagline. */ public function getTagline() { if ($this->_sSource) { return implode('', $this->getMatches(self::IMDB_TAGLINE, 1)); } return 'n/A'; } /** * Get the release date of the current movie. */ public function getTitle() { if ($this->_sSource) { return implode('', $this->getMatches(self::IMDB_TITLE, 1)); } return 'n/A'; } /** * Returns the url. */ public function getUrl() { return $this->_sUrl; } /** * Get the votes of the current movie. */ public function getVotes() { if ($this->_sSource) { return implode('', $this->getMatches(self::IMDB_VOTES, 1)); } return 'n/A'; } /** * Get the year of the current movie. */ public function getYear() { if ($this->_sSource) { return implode('', $this->getMatches(self::IMDB_TITLE, 2)); } return 'n/A'; } /** * Returns the writer(s). */ public function getWriter() { if ($this->_sSource) { $sReturned = $this->getMatches(self::IMDB_WRITER, 4); if (is_array($sReturned)) { return implode(' / ', $sReturned); } return $sReturned; } return 'n/A'; } /** * Returns the writer(s) as link(s). */ public function getWriterAsUrl() { if ($this->_sSource) { $sReturned1 = $this->getMatches(self::IMDB_WRITER, 4); $sReturned2 = $this->getMatches(self::IMDB_WRITER, 1); if (is_array($sReturned1)) { foreach ($sReturned1 as $i => $sWriter) { $aReturn[] = '<a href="http://www.imdb.com/name/' . $sReturned2[$i] . '/">' . $sWriter . '</a>'; } return implode(' / ', $aReturn); } return '<a href="http://www.imdb.com/name/' . $sReturned2 . '/">' . $sReturned1 . '</a>'; } return 'n/A'; } } ?>

    Read the article

  • php Undefined variable: article_id

    - by mmcgrail
    I keep getting this as a warning but but I don't care if its not set so how do I get rid of the warning and still achieve my goal here is the context var url_items = array("foo"); $article_id = db_escape($url_items[1]); $article = get_article($article_id); function get_article($article_id = NULL) {.....}

    Read the article

  • Javascript undefined behavior with string.replace

    - by epochwolf
    I've been messing around with string.replace and I noticed something very odd with Webkit and Firebug's javascript consoles. I can repeat this behavior in a blank browser window. (Look at the first and last lines) >>> "/literature?page=".replace(/page=/i, "page=2") "/literature?page=" >>> "/literature?page=".replace("page=", "page=2") "/literature?page=2" >>> "/literature?page=".replace(/page=/, "page=2") "/literature?page=2" >>> "/literature?page=".replace(/page=/i, "page=2") "/literature?page=2" Just so nobody thinks I mistyped something, here are screenshots. Firebug (3.0.14) Webkit (Latest nightly as of this post's creation.)

    Read the article

  • Undefined offset PHP error

    - by user272899
    I am recieving the following error: Notice indefined offset 1: in C:\wamp\www\includes\imdbgrabber.php line 36 the code is for getting information from IMDB. The link is posted to the page using ajax on another page, I have tested that i am getting the correct response using echo $url <?php $url = $_GET['link']; echo $url; //$url = 'http://www.imdb.com/title/tt0367882/'; //get the page content $imdb_content = get_data($url); //parse for product name $name = get_match('/<title>(.*)<\/title>/isU',$imdb_content); $director = strip_tags(get_match('/<h5[^>]*>Director:<\/h5>(.*)<\/div>/isU',$imdb_content)); $plot = get_match('/<h5[^>]*>Plot:<\/h5>(.*)<\/div>/isU',$imdb_content); $release_date = get_match('/<h5[^>]*>Release Date:<\/h5>(.*)<\/div>/isU',$imdb_content); $mpaa = get_match('/<a href="\/mpaa">MPAA<\/a>:<\/h5>(.*)<\/div>/isU',$imdb_content); $run_time = get_match('/Runtime:<\/h5>(.*)<\/div>/isU',$imdb_content); $rating = get_match('/<div class="starbar-meta">(.*)<\/div>/isU',$imdb_content); ////build content //$content = '<h2>Film</h2><p>'.$name.'</p>' // . '<h2>Director</h2><p>'.$director.'</p>' // . '<h2>Plot</h2><p>'.substr($plot,0,strpos($plot,'<a')).'</p>' // . '<h2>Release Date</h2><p>'.substr($release_date,0,strpos($release_date,'<a')).'</p>' // . '<h2>MPAA</h2><p>'.$mpaa.'</p>' // . '<h2>Run Time</h2><p>'.$run_time.'</p>' // . '<h2>Full Details</h2><p><a href="'.$url.'" rel="nofollow">'.$url.'</a></p>'; //gets the match content function get_match($regex,$content) { preg_match($regex,$content,$matches); return $matches[0]; } //gets the data from a URL function get_data($url) { $ch = curl_init(); $timeout = 5; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); $data = curl_exec($ch); curl_close($ch); return $data; } ?> <!--start infobox--> <div class="info"> <span> <?php echo '<strong>'.$name.'</strong>' ?> </span> <!-- <img src="http://1.bp.blogspot.com/_mySxtRcQIag/S6deHcoChaI/AAAAAAAAObc/Z1Xg3aB_wkU/s200/rising_sun.jpg" /> --> <div class="plot"> <?php echo ''.substr($plot,0,strpos($plot,'<a')).'</div>' ?> </div> <div class="runtime"> <?php echo'<strong>Run Time</strong><br />'.$run_time.'</div>' ?> </div> <div class="releasedate"> <?php echo '<strong>Release Date</strong><br />'.substr($release_date,0,strpos($release_date,'<a')).'</div>' ?> </div> <div class="director"> <?php echo '<strong>Director</strong><br />'.$director.'' ?> </div> <div class="rating"> <?php echo '<strong>Rating</strong><br />'.$rating.'' ?> </div> </div> <!--end infobox-->

    Read the article

  • Undefined / Uninitialized default values in a class

    - by Jir
    Let's suppose you have this class: class A { public: A () {} A (double val) : m_val(val) {} ~A () {} private: double m_val; }; Once I create an instance of A, how can I check if m_val has been initialized/defined? Put it in other words, is there a way to know if m_val has been initialized/defined or not? Something along the lines of the defined operator in Python, I suppose. (But correct me if I'm wrong.) I thought of modifying the class and the c-tors the following way: class A { public: A () : defined(false) {} A (double val) : m_val(val), defined(true) {} ~A () {} private: double m_val; bool defined; }; How do you rate this solution? Any suggestion? TIA, Chris

    Read the article

  • Javascript array value is undefined ... how do I test for that

    - by Ankur
    I am trying to test to see whether a Javascript variable is undefined. You will see that I am not expecting the value of predQuery[preId] to be 'undefined' if I don't first get an alert saying "its unbelievable". But I often do, so I am guessing that my statement predQuery[preId]=='undefined') is not matching the undefined elements properly. if((predQuery.length < preId) || (predQuery[preId]=="") || (predQuery[preId]=='undefined')){ alert("its unbelievable"); alert(predQuery[preId]); queryPreds[variables] = preId; queryObjs[variables] = objId; predQuery[preId] = variables; } else { alert(predQuery[preId]); var predIndex = predQuery[preId]; queryPreds[predIndex] = preId; queryObjs[predIndex] = objId; } I can add more code if needed.

    Read the article

  • Old functions return 'undefined' error once I add a jquery reference

    - by Lapa
    Disregard this question: I've simply confused <script src="..."></script> tag and <script> [some functions] </scipt> tags. I have this function function OnLoad() { ShowHideConfirmAnswers(); return true; } triggered by onload event: <body onload=OnLoad()> It works fine until I add src="jquery-1.4.2.js" to the script element. From this moment I get "OnLoad is not defined" error, and the same happens to every other javascript function.

    Read the article

  • Undefined reference to 'glib'

    - by dali1985
    I would like to parse a config file using glib in Codeblocks which I use. So I want to do exactly the example which is described here first. I have a file named myconfig.cfg and and a code programming.c. I just copy and paste the code to see if glib works but unfortunately it does not work. I did the installation of glib2.0 using sudo apt-get, I found where are the libs in glibs using pkg-config --cflags --libs glib-2.0 and in this path project->Build Options->Compiler Settings-> Other Options I added -I/usr/include/glib-2.0 -I/usr/lib/arm-linuxgnuebihf/glib-2.0/include When I build and run the programming.c I have these errors -------------- Build: Debug in programming --------------- gcc -Wall -g -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include -std=c99 -c /home/pi/Desktop/programming/main.c -o obj/Debug/main.o g++ -o bin/Debug/programming obj/Debug/main.o /usr/lib/libmysqlclient.so.16 obj/Debug/main.o: In function `main': /home/pi/Desktop/programming/main.c:22: undefined reference to `g_key_file_new' /home/pi/Desktop/programming/main.c:26: undefined reference to `g_key_file_load_from_file' /home/pi/Desktop/programming/main.c:28: undefined reference to `g_log' /home/pi/Desktop/programming/main.c:34: undefined reference to `g_slice_alloc' /home/pi/Desktop/programming/main.c:37: undefined reference to `g_key_file_get_string' /home/pi/Desktop/programming/main.c:39: undefined reference to `g_key_file_get_locale_string' /home/pi/Desktop/programming/main.c:41: undefined reference to `g_key_file_get_boolean_list' /home/pi/Desktop/programming/main.c:43: undefined reference to `g_key_file_get_integer_list' /home/pi/Desktop/programming/main.c:45: undefined reference to `g_key_file_get_string_list' /home/pi/Desktop/programming/main.c:47: undefined reference to `g_key_file_get_integer' /home/pi/Desktop/programming/main.c:49: undefined reference to `g_key_file_get_double_list' collect2: ld returned 1 exit status Process terminated with status 1 (0 minutes, 6 seconds) 11 errors, 0 warnings Am I missing something? I tried also to do in the same way with libconfig but again I have undefined reference. Is the problem the path?

    Read the article

  • Division by zero: Undefined Behavior or Implementation Defined in C and/or C++ ?

    - by SiegeX
    Regarding division by zero, the standards say: C99 6.5.5p5 - The result of the / operator is the quotient from the division of the first operand by the second; the result of the % operator is the remainder. In both operations, if the value of the second operand is zero, the behavior is undefined. C++03 5.6.4 - The binary / operator yields the quotient, and the binary % operator yields the remainder from the division of the first expression by the second. If the second operand of / or % is zero the behavior is undefined. If we were to take the above paragraphs at face value, the answer is clearly Undefined Behavior for both languages. However, if we look further down in the C99 standard we see the following paragraph which appears to be contradictory(1): C99 7.12p4 - The macro INFINITY expands to a constant expression of type float representing positive or unsigned infinity, if available; Do the standards have some sort of golden rule where Undefined Behavior cannot be superseded by a (potentially) contradictory statement? Barring that, I don't think it's unreasonable to conclude that if your implementation defines the INFINITY macro, division by zero is defined to be such. However, if your implementation does not define such a macro, the behavior is Undefined. I'm curious what the consensus on this matter for each of the two languages. Would the answer change if we are talking about integer division int i = 1 / 0 versus floating point division float i = 1.0 / 0.0 ? Note (1) The C++03 standard talks about the library which includes the INFINITY macro.

    Read the article

  • Compiling Ubuntu server: "libQtGui.so: undefined reference to png functions" errors

    - by Kowalikus
    I want to compile wkhtmltopdf on Ubuntu Server, but I have a problem with following errors: /usr/lib/libQtGui.so: undefined reference to `png_read_info@PNG12_0' /usr/lib/libQtGui.so: undefined reference to `png_set_gAMA@PNG12_0' /usr/lib/libQtGui.so: undefined reference to `png_set_PLTE@PNG12_0' ... /usr/lib/libQtGui.so: undefined reference to `png_create_info_struct@PNG12_0' /usr/lib/libQtGui.so: undefined reference to `png_set_bgr@PNG12_0' /usr/lib/libQtGui.so: undefined reference to `png_get_valid@PNG12_0' What can I do? in /usr/lib lrwxrwxrwx 1 17 2010-02-17 15:00 libQtGui.so -> libQtGui.so.4.5.2 lrwxrwxrwx 1 17 2010-02-17 14:59 libQtGui.so.4 -> libQtGui.so.4.5.2 lrwxrwxrwx 1 17 2010-02-17 14:59 libQtGui.so.4.5 -> libQtGui.so.4.5.2 -rw-r--r-- 1 10071604 2009-10-14 23:34 libQtGui.so.4.5.2

    Read the article

  • Compiling Ubuntu server: "libQtGui.so: undefined reference to png functions" errors

    - by Kowalikus
    I want to compile wkhtmltopdf on Ubuntu Server, but I have a problem with following errors: /usr/lib/libQtGui.so: undefined reference to `png_read_info@PNG12_0' /usr/lib/libQtGui.so: undefined reference to `png_set_gAMA@PNG12_0' /usr/lib/libQtGui.so: undefined reference to `png_set_PLTE@PNG12_0' ... /usr/lib/libQtGui.so: undefined reference to `png_create_info_struct@PNG12_0' /usr/lib/libQtGui.so: undefined reference to `png_set_bgr@PNG12_0' /usr/lib/libQtGui.so: undefined reference to `png_get_valid@PNG12_0' What can I do? in /usr/lib lrwxrwxrwx 1 17 2010-02-17 15:00 libQtGui.so -> libQtGui.so.4.5.2 lrwxrwxrwx 1 17 2010-02-17 14:59 libQtGui.so.4 -> libQtGui.so.4.5.2 lrwxrwxrwx 1 17 2010-02-17 14:59 libQtGui.so.4.5 -> libQtGui.so.4.5.2 -rw-r--r-- 1 10071604 2009-10-14 23:34 libQtGui.so.4.5.2

    Read the article

  • Setting a variable to undefined

    - by AJ
    Hello, I'm a bit confused about Javascript undefined & null. Firstly what does if (!testvar) actually do? Does it test for undefined and null or just undefined? Secondly, once a variable is defined can I clear it back to undefined (therefore deleting the variable). Thirdly, can I pass undefined as a parameter? e.g: function test(var1, var2, var3) { } test("value1", undefined, "value2") Thanks, AJ

    Read the article

  • Is there a config option in PHP to prevent undefined constants from being interpreted as strings?

    - by mrbinky3000
    This is from the php manual: http://us.php.net/manual/en/language.constants.syntax.php If you use an undefined constant, PHP assumes that you mean the name of the constant itself, just as if you called it as a string (CONSTANT vs "CONSTANT"). An error of level E_NOTICE will be issued when this happens. I really don't like this behavior. If I have failed to define a required constant, I would rather the script fail so that I am forced define it. Is there any way to force PHP to crash the script if it tries to use an undefined constant? For example. Both of these scripts do the same thing. <?php define('DEBUG',1); if (DEBUG) echo('Yo!'); ?> and <?php if(DEBUG) echo('Yo!'); ?> I would rather the second script DIE and declare that it tried to use an undefined constant DEBUG.

    Read the article

  • LLVM-3.1 libLLVMSupport.a undefined reference to `dladdr'

    - by user91387
    I'm trying to compile using the llvm-3.1 package. I'm running 12.04 x64 (3.2.0-26 kernel) && 12.10 (3.5.0-4) x64 backported llvm-3.1 from quantal, then debian experimental. Next I tried 12.10 with the native ubuntu llvm-3.1 package; this failed as well. user@system:/tmp/llvm-test# make compiling cpp yacc file: decaf-llvm.y output file: decaf-llvm bison -b decaf-llvm -d decaf-llvm.y /bin/mv -f decaf-llvm.tab.c decaf-llvm.tab.cc flex -odecaf-llvm.lex.cc decaf-llvm.lex g++ -o ./decaf-llvm decaf-llvm.tab.cc decaf-llvm.lex.cc decaf-stdlib.c `llvm-config --cppflags --ldflags --libs core jit native` -ly -ll /usr/lib/llvm-3.1/lib/libLLVMSupport.a(Signals.o): In function `PrintStackTrace(void*)': (.text+0x6c): undefined reference to `dladdr' /usr/lib/llvm-3.1/lib/libLLVMSupport.a(Signals.o): In function `PrintStackTrace(void*)': (.text+0x18f): undefined reference to `dladdr' collect2: error: ld returned 1 exit status make: *** [decaf-llvm] Error 1 I know the code works as I've run it in centos fine using llvm-3.1-6.fc18(rpm) Google was a bit helpful with this: "On some systems, incluning Ubuntu 11.10, linking may fail with message that libLLVMSupport.a in function PrintStackTrace(void*) has undefined reference to dladdr." "Workaround is to compile LLVM with cmake specifying the following variable: -DCMAKE_EXE_LINKER_FLAGS=-ldl" http://svn.dsource.org/projects/bindings/trunk/llvm-3.0/Readme I double checked y ldflags and everything seems ok. user@system:/llvm-config --ldflags -L/usr/lib/llvm-3.1/lib -lpthread -lffi -ldl -lm I'm unclear of what to do next; any suggestions?

    Read the article

  • Why is x=x++ undefined?

    - by ugoren
    It's undefined because the it modifies x twice between sequence points. The standard says it's undefined, therefore it's undefined. That much I know. But why? My understanding is that forbidding this allows compilers to optimize better. This could have made sense when C was invented, but now seems like a weak argument. If we were to reinvent C today, would we do it this way, or can it be done better? Or maybe there's a deeper problem, that makes it hard to define consistent rules for such expressions, so it's best to forbid them? So suppose we were to reinvent C today. I'd like to suggest simple rules for expressions such as x=x++, which seem to me to work better than the existing rules. I'd like to get your opinion on the suggested rules compared to the existing ones, or other suggestions. Suggested Rules: Between sequence points, order of evaluation is unspecified. Side effects take place immediately. There's no undefined behavior involved. Expressions evaluate to this value or that, but surely won't format your hard disk (strangely, I've never seen an implementation where x=x++ formats the hard disk). Example Expressions x=x++ - Well defined, doesn't change x. First, x is incremented (immediately when x++ is evaluated), then it's old value is stored in x. x++ + ++x - Increments x twice, evaluates to 2*x+2. Though either side may be evaluated first, the result is either x + (x+2) (left side first) or (x+1) + (x+1) (right side first). x = x + (x=3) - Unspecified, x set to either x+3 or 6. If the right side is evaluated first, it's x+3. It's also possible that x=3 is evaluated first, so it's 3+3. In either case, the x=3 assignment happens immediately when x=3 is evaluated, so the value stored is overwritten by the other assignment. x+=(x=3) - Well defined, sets x to 6. You could argue that this is just shorthand for the expression above. But I'd say that += must be executed after x=3, and not in two parts (read x, evaluate x=3, add and store new value). What's the Advantage? Some comments raised this good point. It's not that I'm after the pleasure of using x=x++ in my code. It's a strange and misleading expression. What I want is to be able to understand complicated expressions. Normally, a complicated expression is no more than the sum of its parts. If you understand the parts and the operators combining them, you can understand the whole. C's current behavior seems to deviate from this principle. One assignment plus another assignment suddenly doesn't make two assignments. Today, when I look at x=x++, I can't say what it does. With my suggested rules, I can, by simply examining its components and their relations.

    Read the article

  • Is there a way to catch assignments to or reads from an undefined property in the Spider-Monkey Java

    - by avri
    The Spider-Monkey JavaScript engine implements the noSuchMethod callback function for JavaScript Objects. This function is called whenever JavaScript tries to execute an undefined method of an Object. I would like to set a callback function to an Object that will be called whenever an undefined property in the Object is accessed or assigned to. I haven't found a noSuchProperty function implemented for JavaScript Objects and I am curios if there is any workaround that will achieve the same result.

    Read the article

  • Is there a way to catch assignments to or reads from an undefined property in JavaScript?

    - by avri
    JavaScript implements the noSuchMethod callback function for JavaScript Objects. This function is called whenever JavaScript tries to execute an undefined method of an Object. I would like to set a callback function to an Object that will be called whenever an undefined property in the Object is accessed or assigned to. I haven't found a noSuchProperty function implemented for JavaScript Objects and I am curios if there is any workaround that will achieve the same result.

    Read the article

  • program "is not up to date" execution error in wedit lcc-win32

    - by Rowhawn
    I'm attempting to compile a simple hello world program in c with lcc-win32/wedit, and i'm a little unfamiliar with windows c programming. #include int main(void){ printf("hellow\n"); return 0; } When I compile the program the console output is Wedit output window build: Tue Jun 15 09:13:17 2010 c:\lcc\lib\lcccrt0.obj .text: undefined reference to '_RtlUnwind@16' c:\lcc\lib\lcccrt0.obj .text: undefined reference to '_signal' c:\lcc\lib\lcccrt0.obj .text: undefined reference to '_raise' c:\lcc\lib\lcccrt0.obj .text: undefined reference to '_exit' asctoq.obj .text: undefined reference to '_strnicmp' defaulttrap.obj .text: undefined reference to 'imp_iob' defaulttrap.obj .text: undefined reference to '_fwrite' defaulttrap.obj .text: undefined reference to '_itoa' defaulttrap.obj .text: undefined reference to '_strcat' defaulttrap.obj .text: undefined reference to '_MessageBoxA@16' defaulttrap.obj .text: undefined reference to '_abort' powlasm.obj .text: undefined reference to '_pow' qfloat.obj .text: undefined reference to '_memset' qfloat.obj .text: undefined reference to '_strchr' qfloat.obj .text: undefined reference to '_memmove' strlcpy.obj .text: undefined reference to '_memcpy' xprintf.obj .text: undefined reference to '_localeconv' xprintf.obj .text: undefined reference to '_strtol' xprintf.obj .text: undefined reference to '_wcslen' xprintf.obj .text: undefined reference to '_wctomb' xprintf.obj .text: undefined reference to '_fputc' search Compilation + link time:0.1 sec, Return code: 60 when I attempt to execute the program within wedit i get a dialog box that says "hello.exe is not up-to-date. Rebuild?" If I click yes, nothing happens. If I click no, a dos window pops up saying "C:\lcc\projects\lcc2\hello.exe" Return code -1 Execution time 0.001 seconds Press any key to continue... This continues to happen no matter how many times i compile/rebuild. Any ideas?

    Read the article

  • Undefined behaviour with non-virtual destructors - is it a real-world issue?

    - by Roddy
    Consider the following code: class A { public: A() {} ~A() {} }; class B: public A { B() {} ~B() {} }; A* b = new B; delete b; // undefined behaviour My understanding is that the C++ standard says that deleting b is undefined behaviour - ie, anything could happen. But, in the real world, my experience is that ~A() is always invoked, and the memory is correctly freed. if B introduces any class members with their own destructors, they won't get invoked, but I'm only interested in the simple kind of case above, where inheritance is used maybe to fix a bug in one class method for which source code is unavailable. Obviously this isn't going to be what you want in non-trivial cases, but it is at least consistent. Are you aware of any C++ implementation where the above does NOT happen, for the code shown?

    Read the article

  • When does invoking a member function on a null instance result in undefined behavior?

    - by GMan
    This question arose in the comments of a now-deleted answer to this other question. Our question was asked in the comments by STingRaySC as: Where exactly do we invoke UB? Is it calling a member function through an invalid pointer? Or is it calling a member function that accesses member data through an invalid pointer? With the answer deleted I figured we might as well make it it's own question. Consider the following code: #include <iostream> struct foo { void bar(void) { std::cout << "gman was here" << std::endl; } void baz(void) { x = 5; } int x; }; int main(void) { foo* f = 0; f->bar(); // (a) f->baz(); // (b) } We expect (b) to crash, because there is no corresponding member x for the null pointer. In practice, (a) doesn't crash because the this pointer is never used. Because (b) dereferences the this pointer (this->x = 5;), and this is null, the program enters undefined behavior. Does (a) result in undefined behavior? What about if both functions are static?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >