Thread: Strange compile problem

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    4

    Strange compile problem

    The line
    Code:
    oscOut[i] = sin(oscPhs[i]) * 10000;
    compiles, but the line
    Code:
    oscOut[i] = sin(oscPhs[i]*2.0f*pi) * 10000;
    generates an "expected primary-expression before '=' token" error.

    The line before it is
    Code:
    if (oscSyncPhs[i]>1.0f)  { oscSyncPhs[i]-=1;  oscPhs[i]=oscSyncPhs[i];}

    Possibilities I can think of include:
    -- Bug in g++
    -- Bug in Qt Creator (IDE I'm using)
    -- There's something about the characters "]*" nobody ever told me.
    Last edited by Envergure; 11-30-2008 at 02:34 PM.

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Hmmm your code looks fine to me. Try to rename the "pi" name to "pim" (or whatever, anything random) for a moment. It may be that some header defines pi to something really horrible...
    Or, simply replace it with M_PI .

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Post the smallest and simplest program that demonstrates the error.

    EDIT:
    Quote Originally Posted by EVOEx
    Or, simply replace it with M_PI .
    M_PI is non-standard.
    Last edited by laserlight; 11-30-2008 at 02:43 PM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by laserlight View Post
    M_PI is non-standard.
    Ahh, you're right! I learn something new every day . Thanks!

  5. #5
    Registered User
    Join Date
    Nov 2008
    Posts
    4
    Code:
    #include <iostream>
    #include <cmath>
    #define pi = 3.141592653589793238462643383
    using namespace std;
    
    int main(int argc, char** argv)
    {
    	int i = 0;
    	double oscPhs[3] = {0, 0, 0}, oscOut[3] = {0, 0, 0};
    	oscOut[i] = sin(oscPhs[i]*2.0f*pi) * 10000;
    	cout << oscOut[0];
    	
    	return 0;
    }
    This code reproduces the exact types and names used in the original program I was trying to compile.

    Changine "pi" to "pim" or other variable names doesn't fix it.
    Changing "oscPhs[i]*2.0f*pi" to "2.0f*pi*oscPhs[i]" doesn't fix it.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    The problem is right here:
    Code:
    #define pi = 3.141592653589793238462643383
    You probably wanted to write:
    Code:
    #define pi 3.141592653589793238462643383
    You could avoid a macro with:
    Code:
    const double pi = 3.141592653589793238462643383;
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Nov 2008
    Posts
    4
    Ah - Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strange number problem
    By kkjj in forum C Programming
    Replies: 9
    Last Post: 08-09-2007, 07:30 AM
  2. Basic compile problem
    By luca in forum C++ Programming
    Replies: 14
    Last Post: 01-17-2007, 11:14 PM
  3. problem to compile
    By mohdsuhaili1986 in forum C++ Programming
    Replies: 3
    Last Post: 07-22-2006, 02:48 PM
  4. gcc compile problem
    By keyz in forum Linux Programming
    Replies: 3
    Last Post: 05-22-2003, 07:14 AM
  5. Problem during compile (iostream.h error)
    By JoJo in forum C Programming
    Replies: 4
    Last Post: 04-29-2003, 06:58 PM